Programatically add Boundcolumn in asp.net 2.0 Gridview

Posted by Sudhak under ASP.NET on 5/21/2009 | Views : 4906 | Status : [Member] | Replies : 2
Hi
I have created a GridView in runtime.
I want to add boundcolumns in runtime

please suggest some solutions

Regards,
sudha




Responses

Posted by: Syedshakeer on: 5/22/2009 [Member] Starter

Up
0
Down
Hi Sudhak

<asp:gridview id="grdNorthwindProducts" runat="server"
datasourceid="NorthwindProducts" DataKeyNames="CustomerID" AutoGenerateColumns="False">
<Columns>
<asp:BoundField ReadOnly="True" HeaderText="CustomerID" DataField="CustomerID" SortExpression="CustomerID">
</asp:BoundField>
<asp:BoundField HeaderText="CompanyName" DataField="CompanyName" SortExpression="CompanyName">
</asp:BoundField>

</Columns>
</asp:gridview>

Here Datafield="CustomerId" and CompanyName are Column Name in Table.

in .asp.cs page write below code:

SqlDataAdapter adapter=new SqlCommand("Select CustomerId,CompanyName from Customer",conn);
DataSet ds=new DataSet();
adapter.Fill(ds,"Customer");
Gridview1.DataSource=ds.Tables["Customer"];
Gridview1.DataBind();


Syed Shakeer Hussain

Sudhak, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudhak on: 5/22/2009 [Member] Starter

Up
0
Down
hello,

i was asking about the creation and adding from code behind not from frontend



Sudhak, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response