locked
How to get data corresponding to a selected row in a GridView? RRS feed

  • Question

  • User-1131359042 posted

    I have a grid view which has a column called name and a column which consists of link buttons which hyperlinks to a new form. Now I want this name parameter in a label which is in the new form. I'm using Sessions to do that but the problem is, every time, only the first row get's selected. But I want the name from the row corresponding to that of the hyperlink button which the user clicks on.

    Saturday, July 8, 2017 8:09 AM

Answers

  • User2119946224 posted

    Hi,

    You can do this in many way but one simple way i am putting here:

    <asp:TemplateField HeaderText="ID" HeaderStyle-Wrap="false">
      <ItemTemplate>
        <asp:LinkButton ID="lnkRequestID" runat="server" CommandArgument='<%# Eval("RequestID") %>'
        OnCommand="lnkRequestID_Click" Text='<%# Eval("RequestID") %>' on> </asp:LinkButton>
      </ItemTemplate>
    </asp:TemplateField>

    protected void lnkRequestID_Click(object sender, CommandEventArgs e)
    {
         Session["ABC"] = gv.SelectedDataKey.Value;
    }

    Hope it helps you. If yes please mark as answer.

    Regards,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 8, 2017 10:01 AM

All replies

  • User2119946224 posted

    Hi,

    You can do this in many way but one simple way i am putting here:

    <asp:TemplateField HeaderText="ID" HeaderStyle-Wrap="false">
      <ItemTemplate>
        <asp:LinkButton ID="lnkRequestID" runat="server" CommandArgument='<%# Eval("RequestID") %>'
        OnCommand="lnkRequestID_Click" Text='<%# Eval("RequestID") %>' on> </asp:LinkButton>
      </ItemTemplate>
    </asp:TemplateField>

    protected void lnkRequestID_Click(object sender, CommandEventArgs e)
    {
         Session["ABC"] = gv.SelectedDataKey.Value;
    }

    Hope it helps you. If yes please mark as answer.

    Regards,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 8, 2017 10:01 AM
  • User-1131359042 posted

    Thanks a ton!

    Saturday, July 8, 2017 10:22 AM