problem to creating dynamically gidview

Y

yogesh joshi

when ever i m creating my dynamic gridview not by (asp:gridview). On the
click of the link button its not displaying anything..and if i m
using(asp:gridview) then its working properly..

so plz help me out
my code is..

GridView grid = new GridView();
SqlDataAdapter adp = new SqlDataAdapter("select * from book
", ConfigurationManager.ConnectionStrings["cnn"].ConnectionString);
DataSet ds = new DataSet();
adp.Fill(ds);
//DataColumn dc = new DataColumn();
if (ds.Tables.Count > 0)
{
GridView2.Columns.Clear();
foreach (DataColumn dc in ds.Tables[0].Columns)
{
BoundField bField = new BoundField();
bField.DataField = dc.ColumnName;
bField.HeaderText = dc.ColumnName;
grid.Columns.Add(bField);
}

}
grid.DataSource = ds.Tables[0];
grid.DataBind();
grid.Visible = true;
 
T

Teemu Keiski

Are you at any point adding the grid to Page's Controls collection? E.g say
you have a PAlceHolder on Page

....
<asp:placeHolder ID="PlaceHolder1" runat="server" />
....

After instantiating the grid, add it to the PalceHolder

GridView grid = new GridView();
PlaceHolder1.Controls.Add(grid);

Point is that a control must be in Controls hierarchy of the Page (and its
child controls)in order it to work in any way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top