Я вставляю gridview в свой проект, я помещаю кнопку, чтобы получить идентификатор щелкнутой строки, но каждый раз, когда он возвращает значение «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>
я наконец-то нашел проблему из-за " EditItemTemplate ", когда я удалил, что он работает – SSC