How to Bind Particular Table Columns Bind the Gridview and Dropdownlist.

Jayakumars
Posted by Jayakumars under ASP.NET AJAX category on | Points: 40 | Views : 2906
hi

I have post the sample for
How to Bind Particular Table Columns Bind the Gridview and Dropdownlist.

Client Side Code

<asp:DropDownList ID="DrpColName" runat="server" AutoPostBack="True"
onselectedindexchanged="DrpColName_SelectedIndexChanged" >
</asp:DropDownList>



<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false"
BorderColor="#336699" BorderStyle="Solid" BorderWidth="2px"
CellPadding="4" DataKeyNames="ID"
ForeColor="#333333">

<Columns>

<asp:BoundField DataField="ID" HeaderText="ID"
SortExpression="ID" />

<asp:ButtonField ButtonType="link" CommandName="Column_Name"
DataTextField="Column_Name" HeaderText="Column_Name"
SortExpression="Column_Name" />

</Columns>

</asp:GridView>


server Side Code

if (!IsPostBack)
{
sqlcon.Open();
SqlDataAdapter sqladp = new SqlDataAdapter("SELECT ORDINAL_POSITION as Id,Column_Name FROM Information_Schema.Columns WHERE TABLE_Name = 'UserInformation'", sqlcon);

sqladp.Fill(dt);
DrpColName.DataSource = dt;
DrpColName.DataTextField = "Column_Name";
DrpColName.DataValueField = "Id";
DrpColName.DataBind();
GridView2.DataSource = dt;
GridView2.DataBind();
}

Comments or Responses

Login to post response