C#Gridview第一行数据没有返回

时间:2016-07-06 15:03:56

标签: c# asp.net gridview datagridview

我从数据库加载了Gridview。 Gridview具有BoundFields,Buttons,Textboxes和Dropdown列表。如果我选择任何行但第一行我能够从该行收集数据。如果我选择第一行,我可以看到0被粘贴到Method。下拉列表和文本框为我提供了他们的数据,但是BoundFields没有。

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--%>

文件背后的代码

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 个答案:

答案 0 :(得分:1)

...试

def has_html?(text)
  strip_tags(text) != text
end

...为他人重复相同的模板......

来自文章......

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

HTH

戴夫