Reputation: 49
I have a Gridview loaded from a database. The Gridview has BoundFields, Buttons, Textboxes, and Dropdown lists. If I select any row but the first row I am able to collect the data from that row. If I select the first row I can see the 0 being pasted to the Method. The Dropdown list and the Textboxes give me their data, but the BoundFields do not.
ASP File
<asp:GridView ID="GridViewListComp" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderWidth="2px" Width="1500px"
onrowupdating="GridViewListComp_RowUpdated">
<Columns>
<asp:BoundField DataField="First_Name" HeaderText="First Name" SortExpression="First_Name" />
<asp:BoundField DataField="Last_Name" HeaderText="Last Name" SortExpression="Last_Name" />
<asp:BoundField ItemStyle-Width="75px" DataField="DOB" HeaderText="Date of Birth"
SortExpression="DOB" DataFormatString="{0:MM-dd-yy}" HtmlEncode="false">
<ItemStyle Width="75px"></ItemStyle>
</asp:BoundField>
<%--Policy Text Box Code--%>
<asp:TemplateField HeaderText="Policy">
<ItemTemplate>
<asp:TextBox ID="txtPolicy" runat="server" Text='<%# Eval("[POLICY_NUMBER]") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<%--Policy Text Box END--%>
<%--DropDown Code--%>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<%-- <asp:DropDownList Width="50" runat="server" ID="ddlStatus" AutoPostBack="true" OnLoad="ddlStatus_onload" OnSelectedIndexChanged="ddlStatus_SelectedIndexChanged">--%>
<asp:DropDownList Width="180" runat="server" ID="ddlStatus" AutoPostBack="false" >
<asp:ListItem Text="Review" Value="R"></asp:ListItem>
<asp:ListItem Text="Pending" Value="P"></asp:ListItem>
<asp:ListItem Text="Paid Without Policy" Value="W"></asp:ListItem>
<asp:ListItem Text="Ready to Pay" Value="T"></asp:ListItem>
<asp:ListItem Text="Deduct" Value="D"></asp:ListItem>
<asp:ListItem Text="Matched" Value="M"></asp:ListItem>
<asp:ListItem Text="Paid without Policy Matched" Value="O"></asp:ListItem>
<asp:ListItem Text="Exceeded Payment Override" Value="E"></asp:ListItem>
<asp:ListItem Text="Fixed Cost" Value="F"></asp:ListItem>
<asp:ListItem Text="Other Insured" Value="I"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<%--DropDown Code END--%>
<asp:ButtonField ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" ItemStyle-Width="80px" ControlStyle-Width="70px"
ControlStyle-Height="30px" ButtonType="Button" CommandName="Update" HeaderText="Invoice ID" ShowHeader="True" Text="Update" />
<%--Paid Amount Text Box Code--%>
<asp:TemplateField HeaderText="Paid Amount">
<ItemTemplate>$<br />
<asp:TextBox Width="75px" ID="PAID_AMT" runat="server" Text='<%# Eval("[PAID_AMT]") %>' ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<%--Paid Amount Text Box END--%>
Code Behind File
protected void GridViewListComp_RowUpdated(object sender, GridViewUpdateEventArgs e)
{
int grIndex = e.RowIndex;
GridViewRow rowGr = GridViewListComp.Rows[grIndex];
string txtFName = GridViewListComp.Rows[grIndex].Cells[0].Text;
string txtLName = GridViewListComp.Rows[grIndex].Cells[1].Text;
string txtDOB = GridViewListComp.Rows[grIndex].Cells[2].Text;
string txtPolicy = ((TextBox)GridViewListComp.Rows[grIndex].FindControl("txtPolicy")).Text;
DropDownList ddl = GridViewListComp.Rows[grIndex].FindControl("ddlStatus") as DropDownList;
//gets the value of Status Dropdown list
string valueStatus = ddl.SelectedValue.ToString(); //This gets the value of Status
string txtPaidAmt = ((TextBox)GridViewListComp.Rows[grIndex].FindControl("PAID_AMT")).Text;
Upvotes: 3
Views: 687
Reputation: 740
Try...
string txtFName = ((TextBox)GridViewListComp.Rows[grIndex].Cells[0].Controls[0]).Text;
...repeat same template for others...
From article...
HTH
Dave
Upvotes: 1