Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > problem to creating dynamically gidview

Reply
Thread Tools

problem to creating dynamically gidview

 
 
yogesh joshi
Guest
Posts: n/a
 
      02-07-2007


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;

*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      02-15-2007
Are you at any point adding the grid to Page's Controls collection? E.g say
you have a PAlceHolder on Page

....
<asplaceHolder 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.


--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net



"yogesh joshi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
>
> 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;
>
> *** Sent via Developersdex http://www.developersdex.com ***


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A problem of dynamically creating a control s9213037@gmail.com ASP .Net 3 03-22-2007 01:17 PM
Accessing GidView cells from JS ? Mr. Murad Jamal ASP .Net Building Controls 0 06-01-2006 01:03 PM
Security problem when dynamically creating directories Eran Kampf ASP .Net Security 6 10-15-2004 11:29 AM
Problem with Dynamically Creating Link Buttons Burak ASP .Net Building Controls 1 09-18-2003 11:00 PM
Re: Dynamically creating graphic and image map problem. Jacky Kwok ASP .Net 2 08-14-2003 01:24 PM



Advertisments