Simple thing get a list of columns present in the binded grid view, that’s it,
but gives errors.
Try to get the number of columns also does not work! it says zero?
Here’s the code:
try
{
commandString = "Select * from Table_1";
conn = new SqlConnection(Class1.connection);
command = new SqlCommand(commandString, conn);
conn.Open();
reader = command.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
//also not wrking??
Label1.Text = GridView1.Columns.Count.ToString;
reader.Close();
reader.Dispose();
conn.Close();
conn.Dispose();
What’s wrong? Is there an alternate way to ask grid view for its columns? autogenerate columns is true.
This is how I achieved it. If any better coding is possible, please do comment.