第一行数据不返回

时间:2022-05-20 14:46:26

I have a Gridview loaded from a database. The Gridview has BoundFields, Buttons, Textboxes, and Dropdown lists. If I select any row but the first row I am able to collect the data from that row. If I select the first row I can see the 0 being pasted to the Method. The Dropdown list and the Textboxes give me their data, but the BoundFields do not.

我有一个从数据库加载的Gridview。Gridview有BoundFields、按钮、文本框和下拉列表。如果我选择了第一行之外的任何一行,我就能够从这一行中收集数据。如果我选择第一行,我可以看到将0粘贴到该方法。下拉列表和文本框提供了它们的数据,但BoundFields没有。

ASP File

ASP文件

<asp:GridView ID="GridViewListComp" runat="server" AutoGenerateColumns="False" BackColor="White"
    BorderWidth="2px" Width="1500px" 
        onrowupdating="GridViewListComp_RowUpdated">

    <Columns>    
        <asp:BoundField DataField="First_Name" HeaderText="First Name" SortExpression="First_Name" />

        <asp:BoundField DataField="Last_Name" HeaderText="Last Name" SortExpression="Last_Name" />

        <asp:BoundField ItemStyle-Width="75px" DataField="DOB" HeaderText="Date of Birth"
            SortExpression="DOB" DataFormatString="{0:MM-dd-yy}" HtmlEncode="false">
            <ItemStyle Width="75px"></ItemStyle>
        </asp:BoundField>


        <%--Policy Text Box Code--%>
        <asp:TemplateField HeaderText="Policy">
            <ItemTemplate>
                <asp:TextBox ID="txtPolicy" runat="server" Text='<%# Eval("[POLICY_NUMBER]") %>'></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <%--Policy Text Box END--%>

    <%--DropDown Code--%>
        <asp:TemplateField HeaderText="Status">
            <ItemTemplate>
                <%-- <asp:DropDownList Width="50" runat="server" ID="ddlStatus" AutoPostBack="true" OnLoad="ddlStatus_onload" OnSelectedIndexChanged="ddlStatus_SelectedIndexChanged">--%>
                <asp:DropDownList Width="180" runat="server" ID="ddlStatus" AutoPostBack="false" >
                    <asp:ListItem Text="Review" Value="R"></asp:ListItem>
                    <asp:ListItem Text="Pending" Value="P"></asp:ListItem>
                    <asp:ListItem Text="Paid Without Policy" Value="W"></asp:ListItem>
                    <asp:ListItem Text="Ready to Pay" Value="T"></asp:ListItem>
                    <asp:ListItem Text="Deduct" Value="D"></asp:ListItem>
                    <asp:ListItem Text="Matched" Value="M"></asp:ListItem>
                    <asp:ListItem Text="Paid without Policy Matched" Value="O"></asp:ListItem>
                    <asp:ListItem Text="Exceeded Payment Override" Value="E"></asp:ListItem>
                    <asp:ListItem Text="Fixed Cost" Value="F"></asp:ListItem>
                    <asp:ListItem Text="Other Insured" Value="I"></asp:ListItem>
                </asp:DropDownList>
            </ItemTemplate>
        </asp:TemplateField>
        <%--DropDown Code END--%>

        <asp:ButtonField ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" ItemStyle-Width="80px" ControlStyle-Width="70px" 
        ControlStyle-Height="30px" ButtonType="Button" CommandName="Update" HeaderText="Invoice ID" ShowHeader="True" Text="Update" /> 

        <%--Paid Amount Text Box Code--%>
        <asp:TemplateField HeaderText="Paid Amount">
            <ItemTemplate>$<br />
                <asp:TextBox Width="75px" ID="PAID_AMT" runat="server" Text='<%# Eval("[PAID_AMT]") %>' ></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <%--Paid Amount Text Box END--%>

Code Behind File

背后的代码文件

protected void GridViewListComp_RowUpdated(object sender, GridViewUpdateEventArgs e)
    {

        int grIndex = e.RowIndex;
        GridViewRow rowGr = GridViewListComp.Rows[grIndex];
        string txtFName = GridViewListComp.Rows[grIndex].Cells[0].Text;
        string txtLName = GridViewListComp.Rows[grIndex].Cells[1].Text;
        string txtDOB = GridViewListComp.Rows[grIndex].Cells[2].Text;
        string txtPolicy = ((TextBox)GridViewListComp.Rows[grIndex].FindControl("txtPolicy")).Text; 

        DropDownList ddl = GridViewListComp.Rows[grIndex].FindControl("ddlStatus") as DropDownList;

        //gets the value of Status Dropdown list
        string valueStatus = ddl.SelectedValue.ToString(); //This gets the value of Status


        string txtPaidAmt = ((TextBox)GridViewListComp.Rows[grIndex].FindControl("PAID_AMT")).Text; 

1 个解决方案

#1


1  

Try...

试一试……

string txtFName = ((TextBox)GridViewListComp.Rows[grIndex].Cells[0].Controls[0]).Text;

...repeat same template for others...

…为别人重复同样的模板……

From article...

从文章…

http://forums.asp.net/t/1332603.aspx?How+to+retrive+Boundfield+value+of+gridview+on+rowupdating+event

http://forums.asp.net/t/1332603.aspx?How + +索取+ Boundfield +价值+ +显示数据表格+ + rowupdating事件

HTH

HTH

Dave

戴夫

#1


1  

Try...

试一试……

string txtFName = ((TextBox)GridViewListComp.Rows[grIndex].Cells[0].Controls[0]).Text;

...repeat same template for others...

…为别人重复同样的模板……

From article...

从文章…

http://forums.asp.net/t/1332603.aspx?How+to+retrive+Boundfield+value+of+gridview+on+rowupdating+event

http://forums.asp.net/t/1332603.aspx?How + +索取+ Boundfield +价值+ +显示数据表格+ + rowupdating事件

HTH

HTH

Dave

戴夫