Click here to Skip to main content
15,911,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I have GridView & i binded CategoryID with DataKeyNames.
DataKeyNames="CategoryID"

I have link button in my GridView.

When i click that link button i need to get that row CategoryID.

Which event i need to write for this link button & how to do this?
Posted

hi,
you can define CommandArgument and CommandName for your link button,For example :
ASP.NET
<ItemTemplate>
<asp:LinkButton ID="user" runat="server" CssClass="grid_Link" CommandArgument='<%# Eval("idHuman") %>' CommandName="Edit" Text='<%# Eval("userName") %>'></asp:LinkButton>
</ItemTemplate>


and in RowCommand event of gridview get commandArgument :
C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "Edit":
                {
                    string userName = e.CommandArgument.ToString();
                }
                break;
        }
    }
 
Share this answer
 
v3
Hi,
You need to use LinkButton_Command of your LinkButton. Just set the CommandName of the LinkButton to something(for instance 'Select') and Bind the CategoryId to it's CommandArgument. Then, on LinkButton_Command you can get the CategoryId of that row which it's LinkButton is clicked.

I hope it helps,
Cheers.
 
Share this answer
 
Try this in Row Command event of grid view

C#
int rowindex = Convert.ToInt32(e.CommandArgument);
int MRLID = Convert.ToInt32(gvMRLSearch.DataKeys[rowindex].Value); //gvMRLSearch is gridview name
 
Share this answer
 
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
switch (e.CommandName)
{
case "Edit":
{
string userName = e.CommandArgument.ToString();
}
break;
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900