我想通过单击外部按钮来计算具有 textbox.text !=null 的行但是当我尝试 row.findcontrol 它的 null 这是我的代码
<asp:GridView ID="GridViewCellNo" runat="server" AutoGenerateColumns="False" BorderStyle="None"
GridLines="None" OnRowDataBound="GridViewAddCellNumber_RowDataBound" ShowFooter="True"
ShowHeader="false">
<Columns>
<asp:TemplateField ItemStyle-Width="200px">
<ItemTemplate>
<asp:Label ID="LabelGVCellRowNo" runat="server" Text='<%#Eval("CellRowNumber")%>'
Visible="false"></asp:Label>
<asp:TextBox ID="TextBoxCellNo" runat="server" Text='<%#Eval("CellNumber")%>' Width="350px"></asp:TextBox>
<asp:RegularExpressionValidator ID="REVCellNumber" runat="server" ControlToValidate="TextBoxCellNo"
CssClass="ErroreMessage" Display="None" ErrorMessage="<b>Required Field Missing</b><br />Please enter the phone number(digits only)."
SetFocusOnError="True" ValidationExpression="^[0-9]*$"></asp:RegularExpressionValidator>
<asp:ValidatorCalloutExtender ID="VCOE_REVPhoneNumber" runat="Server" HighlightCssClass="validatorCalloutHighlight"
TargetControlID="REVCellNumber">
</asp:ValidatorCalloutExtender>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TextBoxAddCellNum" runat="server" Width="350px"></asp:TextBox>
<asp:RegularExpressionValidator ID="REVCellNumber" runat="server" ControlToValidate="TextBoxAddCellNum" CssClass="ErroreMessage" Display="None" ErrorMessage="<b>Required Field Missing</b><br />Please enter the phone number(digits only)."
SetFocusOnError="True" ValidationExpression="^[0-9]*$"></asp:RegularExpressionValidator>
<asp:ValidatorCalloutExtender ID="VCOE_REVPhoneNumber" runat="Server" HighlightCssClass="validatorCalloutHighlight"
TargetControlID="REVCellNumber">
</asp:ValidatorCalloutExtender>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField FooterStyle-HorizontalAlign="left" ItemStyle-HorizontalAlign="left"
ItemStyle-Width="200px" ShowHeader="False">
<FooterTemplate>
<table>
<tr>
<td width="20px">
</td>
<td>
<asp:Button ID="addAttributeGridViewCellNoButtonAdd" runat="server" CausesValidation="true" Text="+" OnClick="GridViewAddCellNumberButtonAdd_Click" ToolTip="Add" ValidationGroup="AddCellNo" Width="30px" OnClientClick="showProgress()" />
</td>
<td>
Add another number
</td>
</tr>
</table>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
当我在下面的按钮单击事件上运行此函数时,它会给出 txtCellno =null
private int GridViewCellNoCount()
{
int cellCount = 0;
foreach (GridViewRow row in GridViewCellNo.Rows)
{
TextBox txtCellno = row.FindControl("TextBoxAddCellNum") as TextBox;
//if (((TextBox)row.FindControl("TextBoxAddCellNum")).Text.Length > 0)
if (txtCellno.Text.Length > 0)
{
cellCount++;
}
}
return cellCount;