我想计算具有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;