views:

27

answers:

1

I have a gridview with a boundfield and a templatefield (textbox). I'd like to iterate through the rows of the grid and get the underlying data out, including the data key for the grid rows themselves.

Given the following gridview row elements, how would I go about reverse engineering the data?

<asp:BoundField HeaderText="Due Date" DataField="DueDate" 
       SortExpression="DueDate"
        DataFormatString="{0:M/dd/yyyy}"
       ></asp:BoundField>


     <asp:TemplateField HeaderText="Quota">
   <ItemTemplate>  
    <asp:TextBox ID="txtDraftQuota" runat="server" Width="25px" MaxLength="3" 
    Value='<%# Eval("Quota") %>' />
   </ItemTemplate>
  </asp:TemplateField>
+1  A: 

Something like this?

foreach (GridViewRow row in GridView1.Rows)
{
  string dueDate = row.Cells[0].Text;
  string quota = ((TextBox)row.Cells[1].FindControl("txtDraftQuota")).Text;

  //Do something with these values
}
Germ