Thanks Teemu for your informative inputs.
Hi Alex,
Do you think the "AutogeneratedC olumns" option is suitable for your
scenario. Based on my understanding, if you do not want to design any
column/layout for the Gridview or Table at design-time, you will need to
completely do them in code at runtime. And I suggest you consider directly
use the ASP.NET Table control and dynamically creating the tablerows and
tablecells(Tabl e control is much more flexible than gridview or other
databound based control). For example, the following code dynamically
populate a ASP.NET table control through the data reading from a DataReader:
#there is an emtpy ASP.NET Table control on the page:
=============== ===========
protected void Page_Load(objec t sender, EventArgs e)
{
PopulateTable() ;
}
protected void PopulateTable()
{
SqlConnection conn = new
SqlConnection(W ebConfiguration Manager.Connect ionStrings["LocalNorthWind "].Co
nnectionString) ;
conn.Open();
SqlCommand comm = new SqlCommand("sel ect CategoryID, CategoryName,
Description from categories", conn);
SqlDataReader reader = comm.ExecuteRea der();
int cols = reader.FieldCou nt;
TableHeaderRow thr = new TableHeaderRow( );
for (int i = 0; i < cols; i++)
{
TableHeaderCell thc = new TableHeaderCell ();
thc.Text = reader.GetName( i);
thr.Cells.Add(t hc);
}
Table1.Rows.Add (thr);
while (reader.Read())
{
TableRow tr = new TableRow();
for (int i = 0; i < cols; i++)
{
TableCell tc = new TableCell();
tc.Text = reader.GetValue (i).ToString();
tr.Cells.Add(tc );
}
Table1.Rows.Add (tr);
}
reader.Close();
conn.Close();
}
=============== =============== ===
also, if you have queried multiple results in the datareader, you can use
the DataReader.Next Result method to get the next resultset (after you've
finishing looping through the former resultset).
Hope this helps.
Regards,
Steven Cheng
Microsoft MSDN Online Support Lead
=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)