【发布时间】:2021-05-26 07:03:47
【问题描述】:
基本上是在选中复选框时尝试捕获信息,如果是则捕获输入的数量。附上代码。
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox ID="TextboxQuantity" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
这是我的 aspx.cs 代码。
//check to see if a check box is checked
for (int row = 0; row < gv_Input.Rows.Count; row++)
{
CheckBox Cbox = (CheckBox)gv_Input.Rows[row].FindControl("CheckboxSelect");
TextBox Tbox = (TextBox)gv_Input.Rows[row].FindControl("TextboxQuantity");
int quantity = Convert.ToInt32(Tbox.Text);
if (Cbox.Checked)
{
if (Tbox == null)
{
Response.Write("<script>alert('Fill in textbox')</script>");
}
else
{
Response.Write(
"<script>alert('Something was inputted into the textbox')</script>");
}
}
}
给出错误的行是这一行
int quantity = Convert.ToInt32(Tbox.Text);
错误: 输入字符串的格式不正确
【问题讨论】:
-
请edit 提出问题,以便准确显示失败的行并包含该行的数据。理想情况下,将代码缩短到包含硬编码数据的那一行(如
int quantity = Convert.ToInt32("salmon");)。 -
刚刚编辑了我的问题我很抱歉@AlexeiLevenkov
标签: c# asp.net gridview findcontrol