I have a form that pulls back some data for the user to update in the DB. I pull this into a GridView
. I have a checkbox and a textbox for input on the field that was returned from the DB. I cannot figure out how to access the data that the user has inputted; it keeps coming back as empty strings (or false, in the case of the checkbox). Here is my front end code:
<asp:GridView ID="missingCounties" runat="server" Width="300px" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" AutoGenerateColumns="False" OnRowCommand="newCountyInformation" DataKeyNames= "guID">
<Columns>
<asp:BoundField DataField="guID" HeaderText="guID" Visible="False"></asp:BoundField>
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName"></asp:BoundField>
<asp:TemplateField>
<HeaderTemplate>Is %</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="percent" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Fee</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="fee" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Submit</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton runat="server" CommandName="SubmitNewCounty" Width="100px" Text="Submit" CommandArgument="<%#((GridViewRow)Container).RowIndex %>"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<asp:Label ID="Label2" runat="server" Text="No new counties found."></asp:Label>
</EmptyDataTemplate>
</asp:GridView>
Here is what I've tried on the back end:
protected void newCountyInformation(object sender, GridViewCommandEventArgs e)
{
var index = Convert.ToInt32(e.CommandArgument);
var guID = missingCounties.DataKeys[index]["guID"].ToString();
if (string.Equals(e.CommandName.ToLower(), "submitnewcounty"))
{
var percent = (CheckBox)missingCounties.Rows[index].Cells[2].FindControl("percent");
var fee = (TextBox)missingCounties.Rows[index].Cells[3].FindControl("fee");
}
}
In the backend, I've tried different things, such as: missingCounties.Rows[index].Cells[2].Text
. Where am I going wrong with getting the user input data back?
As a disclaimer, I have looked over many similar questions on SO, but none of them have addressed/resolved this particular issue.