2016-07-06 90 views
3

我有一個從數據庫加載的Gridview。 Gridview有BoundFields,Buttons,Textboxes和Dropdown列表。如果我選擇任何行,但第一行,我能夠從該行收集數據。如果我選擇第一行,我可以看到0被粘貼到方法。下拉列表和文本框給我他們的數據,但是BoundFields沒有。C#Gridview第一行數據不返回

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; 
+0

就在不檢查的頭頂上......做了綁定字段需要一個「值」或「文本」屬性設置,使得數據字段設置爲文本/值屬性(即Text =「{0}」...)只是在黑暗中拍攝 – Dave

+0

謝謝Dave,我不確定你有沒有一個可能看起來像什麼的例子。 – MeGreeny

+0

我發現的唯一的事情是DataFormatString =「{0}」,因此可能無法正常工作......可能對您有解決方案... – Dave

回答