2017-02-08 6 views
0

選択ボタンリンクを使用してグリッドビューから行を選択しようとしていますが、ボタンをクリックしてもそのC#メソッドは呼び出されません。それで、私は何が間違っているのだろうかと思っています。私を助けてください。おかげasp.netのgridviewから行を選択しますか?

form.aspx-

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    OnRowEditing="OnRowEditing" OnRowCancelingEdit="OnRowCancelingEdit" 
    OnRowUpdating="OnRowUpdating" OnRowDeleting="OnRowDeleting" EmptyDataText="No records has been added." Height="72px" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Width="723px"> 
    <Columns> 
     <asp:TemplateField HeaderText="Title" ItemStyle-Width="150"> 
      <ItemTemplate> 
       <asp:Label ID="lbltitle" runat="server" Text='<%# Eval("Title") %>'></asp:Label> 
      </ItemTemplate> 
      <EditItemTemplate> 
       <asp:TextBox ID="txttitle" runat="server" Text='<%# Eval("Title") %>'></asp:TextBox> 
      </EditItemTemplate> 
      <ItemStyle Width="150px"></ItemStyle> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Subtitle" ItemStyle-Width="150"> 
      <ItemTemplate> 
       <asp:Label ID="lblsubtitle" runat="server" Text='<%# Eval("Subtitle") %>'></asp:Label> 
      </ItemTemplate> 
      <EditItemTemplate> 
       <asp:TextBox ID="txtsubtitle" runat="server" Text='<%# Eval("Subtitle") %>'></asp:TextBox> 
      </EditItemTemplate> 
      <ItemStyle Width="150px"></ItemStyle> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Content" ItemStyle-Width="150"> 
      <ItemTemplate> 
       <asp:Label ID="lblContent" runat="server" Text='<%# Eval("Content") %>'></asp:Label> 
      </ItemTemplate> 
      <EditItemTemplate> 
       <asp:TextBox ID="txtContent" runat="server" Text='<%# Eval("Content") %>'></asp:TextBox> 
      </EditItemTemplate> 
      <ItemStyle Width="150px"></ItemStyle> 
     </asp:TemplateField> 
     <asp:TemplateField> 
      <ItemTemplate> 
       <asp:LinkButton ID="LinkButton1" runat="server" Text="SELECT" CommandName="MyCustomCommand" /> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 

NewsFeedDemo.cs

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName.Equals("MyCustomCommand")) 
    { 
     GridViewRow clickedRow = ((LinkButton)e.CommandSource).NamingContainer as GridViewRow; 
     Label lblID = (Label)clickedRow.FindControl("lblID"); 
    } 
} 

答えて

0

は、メソッドGridView1_RowCommandを使用して、このOnRowCommand="GridView1_RowCommand"

<asp:LinkButton ID="lnkbedit" runat="server" CommandName="MyCustomCommand" CommandArgument='<%#Eval("id") %>'>Edit</asp:LinkButton> 

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
    { 
    if (e.CommandName == "Edit") 
      { 
      } 
    } 
0

を使用しますが、それはGridView1にバインドされていませんしてください。 GridViewにOnRowCommandを追加する必要があります。

​​
関連する問題