H
hartbypass
Hello all.
I am trying to interate thorugh by GridView data to pump each cell of
each row into a stored proc to load to a DB. I seem to be having a
heck of a time getting the Columns.Count to work for my interation and
I am starting to wonder if I am missing something in what that Count
method should return.
The data is loading perfectly into my GridView control.
I started with this:
foreach (GridViewRow row in GridView1.Rows)
{
for (int c = 0; c <= GridView1.Columns.Count; c++)
{
Response.Write(row.Cells[c].Text + "<br />");
}
}
and I get 0 for the column count, so obviously it doesn't work.
So I changed to
foreach (GridViewRow row in GridView1.Rows)
{
for (int c = 0; c < 13; c++)
{
Response.Write(row.Cells[c].Text + "<br />");
}
}
and it worked, but I don't want to asume less than 13 columns.
I put a couple Response.Writes right after my GridView load to make
sure I wasn't doing some postback in the process and I get
7 - Which is correct
0 - Which is not
I have this as the code for the above:
GridView1.DataSource = dsDatasetName;
GridView1.DataBind();
Response.Write("<br/ >" + GridView1.Columns.Count);
Response.Write("<br/ >" + GridView1.Rows.Count);
I have not done anything special to the HTML side of things:
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
Thoughts?
I am trying to interate thorugh by GridView data to pump each cell of
each row into a stored proc to load to a DB. I seem to be having a
heck of a time getting the Columns.Count to work for my interation and
I am starting to wonder if I am missing something in what that Count
method should return.
The data is loading perfectly into my GridView control.
I started with this:
foreach (GridViewRow row in GridView1.Rows)
{
for (int c = 0; c <= GridView1.Columns.Count; c++)
{
Response.Write(row.Cells[c].Text + "<br />");
}
}
and I get 0 for the column count, so obviously it doesn't work.
So I changed to
foreach (GridViewRow row in GridView1.Rows)
{
for (int c = 0; c < 13; c++)
{
Response.Write(row.Cells[c].Text + "<br />");
}
}
and it worked, but I don't want to asume less than 13 columns.
I put a couple Response.Writes right after my GridView load to make
sure I wasn't doing some postback in the process and I get
7 - Which is correct
0 - Which is not
I have this as the code for the above:
GridView1.DataSource = dsDatasetName;
GridView1.DataBind();
Response.Write("<br/ >" + GridView1.Columns.Count);
Response.Write("<br/ >" + GridView1.Rows.Count);
I have not done anything special to the HTML side of things:
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
Thoughts?