开发者

Why can I not obtain the value of a textbox in a FormView?

开发者 https://www.devze.com 2023-03-17 06:30 出处:网络
So, I was having some issues obtaining the value of of an ASP TextBox Server Control while it was in a FormView.Here is the code.

So, I was having some issues obtaining the value of of an ASP TextBox Server Control while it was in a FormView. Here is the code.

<EditItemTemplate>
                    <table>
                            <tr>
                                <td>
                                    <div style="margin-bottom: 10px; font-family:Calibri;">
                                        Project Number
                                    </div>
                                </td>
                                <td colspan="2">
                                    <asp:TextBox ID="projectidbox" runat="server" Width="90%" Style="margin-bottom: 10px;"
                                        Text='<%# Bind("ProjectID") %>'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td style=" font-family:Calibri;">
                                    Project Name
                                </td>
                                <td>
                                    <asp:TextBox ID="NameBox" runat="server" Width="90%" Text='<%# Bind("Name") %>'> </asp:TextBox>
                                </td>
                                <td style=" font-family:Calibri;">
                                    Project Start
                                </td>
                                <td>
                                    <asp:TextBox ID="dateStartedBox" runat="server" Width="90%" Text='<%# Bind("DateStarted")%>'></asp:TextBox>
                                </td>
                                <td style=" font-family:Calibri;">
                                    Project End
                                </td>
                                <td>
                                    <asp:TextBox ID="dateFinishedBox" runat="server" Width="102%" Text='<%# Bind("DateFinished")%>'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td style=" font-family:Calibri;">
                                    Total Cost ($)
                                </td>
                                <td>
                                    <asp:TextBox ID="TotalCostBox" runat="server" Width="90%" Text='<%# Bind("TotalCost")%>'></asp:TextBox>
                                </td>
                                <td style=" font-family:Calibri;">
                                    Assess. Start
                                </td>
                                <td>
                                    <asp:TextBox ID="assessmentStartBox" runat="server" Width="70%" Text='<%# Bind("BeginTerm")%>'></asp:TextBox>
                                </td>
                                <td style=" font-family:Calibri;">
                                    Assess. End
                                </td>
                                <td>
                                    <asp:TextBox ID="assessmentEndBox" runat="server" Width="90%" Text='<%# Bind("EndTerm")%>'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td style=" font-family:Calibri;">
                                    Assessable Area
                                </td>
                                <td>
                                    <asp:TextBox ID="AssessableFrontageBox" runat="server" Width="90%" Text='<%# Bind("AssessableFrontage")%>'></asp:TextBox>
                                </td>
                                <td style=" font-family:Calibri;">
                                    Ordinance
                                </td>
                                <td>
                                    <asp:TextBox ID="ordinancebox" runat="server" Width="70%" Text='<%# Bind("Ordinance")%>'></asp:TextBox>
                                </td>
                                <td style=" font-family:Calibri;">
                                    Calc Field
                                </td>
                                <td>
                                    <asp:TextBox ID="calcfieldbox" runat="server" Width="90%" Text='<%# Bind("CalcField")%>'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td style=" font-family:Calibri;">
                                    Total Intersections
                                </td>
                                <td>
                                    <asp:TextBox ID="intersectionsbox" runat="server" Width="90%" Text='<%# Bind("TotalIntersections") %>'></asp:TextBox>
                                </td>
                                <td style=" font-family:Calibri;">
                                    County ID
                                </td>
                                <td>
                                    <asp:TextBox ID="countyidbox" runat="server" Width="70%" Text='<%# Bind("CountyID") %>'></asp:TextBox>
                                </td>
                                <td style=" font-family:Calibri;">
                                    Adjustment
                                </td>
                                <td>
                                    <asp:TextBox ID="adjustmentbox" runat="server" Width="90%" Text='<%# Bind("Adjustment") %>'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td style=" font-family:Calibri;">
                                    Sum Assessments
                                </td>

                                <td>
                                    <asp:TextBox ID="sumassessbox" runat="server" Width="90%" Text='<%# Eval("SumAssessments")%>'></asp:TextBox>
                                </td>
                                <td style=" font-family:Calibri;">
                                    Status
                                </td>
          开发者_StackOverflow中文版                      <td>
                                    <asp:DropDownList ID="DropDownList1" runat="server" Width="75%" Height="22px" DataValueField="Status">
                                        <asp:ListItem></asp:ListItem>
                                        <asp:ListItem>Pre-Planning</asp:ListItem>
                                        <asp:ListItem>Active</asp:ListItem>
                                        <asp:ListItem>Complete</asp:ListItem>
                                        <asp:ListItem>Cancelled</asp:ListItem>

                                    </asp:DropDownList>
                                </td>
                                <td colspan="2">
                                    <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
                                        <asp:ListItem>Ln Ft</asp:ListItem>
                                        <asp:ListItem>Acre</asp:ListItem>
                                        <asp:ListItem>Flat</asp:ListItem>
                                    </asp:RadioButtonList>
                                </td>
                            </tr>
                            <tr>
                            <td style="font-family:Calibri;"> Comments </td>
                            </tr>
                            <tr>
                                <td colspan="6">
                                    <asp:TextBox ID="TextBox9" runat="server" TextMode="MultiLine" Width="90%" Text='<%# Bind("Comment") %>'></asp:TextBox>
                                </td>
                            </tr>

                        </table>
                    </EditItemTemplate>


You can use the FindControl function to seach for the text box.

var textbox = (TextBox)GridView.FindControl("txtName);
if (textbox != null)
{
   //working goes here.
}
0

精彩评论

暂无评论...
验证码 换一张
取 消