2014-01-26 22 views
-2

我插入一个gridview到我的项目中,我把一个按钮来获取点击行的id,但每次它返回“0”值。Datagridview不返回行的编号

if (e.CommandName == "editrecord") 
     { 

      int index = Convert.ToInt32(e.CommandArgument); 
      GridViewRow row = GridView1.Rows[index]; 

      txtBrand.Text = row.Cells[0].Text; 

     } 

这里是我的GridView控件代码:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowCommand="GridView1_RowCommand"> 
     <AlternatingRowStyle BackColor="White" /> 
     <Columns> 
      <asp:BoundField DataField="SubProductId" HeaderText="شماره " /> 
      <asp:TemplateField HeaderText="برند "> 
       <EditItemTemplate> 
        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("SubProductName") %>'></asp:TextBox> 
       </EditItemTemplate> 
       <ItemTemplate> 
        <asp:Label ID="Label1" runat="server" Text='<%# Bind("SubProductName") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:ButtonField ButtonType="Image" CommandName="editrecord" HeaderText="ویرایش" ImageUrl="~/adminPortal/Images/edit.png" /> 
     </Columns> 
     <EditRowStyle BackColor="#2461BF" /> 
     <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> 
     <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> 
     <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> 
     <RowStyle BackColor="#EFF3FB" /> 
     <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> 
     <SortedAscendingCellStyle BackColor="#F5F7FB" /> 
     <SortedAscendingHeaderStyle BackColor="#6D95E1" /> 
     <SortedDescendingCellStyle BackColor="#E9EBEF" /> 
     <SortedDescendingHeaderStyle BackColor="#4870BE" /> 
    </asp:GridView> 
+0

我终于发现了问题是因为“ EditItemTemplate“当我删除它的作品 – SSC

回答

0

我终于发现,这个问题是因为“EditItemTemplate中”当我删除,它的作品

+0

然后,请将此标记为答案。 – SANN3

+0

我不能因为堆栈说你应该在2天后标记它 – SSC