Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello Everyone..!!
I have a data grid in which first two columns are item templates containing buttons.

I have a row_command event where i check the command name property of
particular button.

i want to check which row button is checked

i have used the following code.
but it is not working.

C#
if (e.CommandName=="rate")
        {
            int index = Convert.ToInt32(e.CommandArgument);

            GridViewRow gr = grdOTIF.Rows[index];
         }


Kindly help me with the same.
Posted

Change as Below :

<asp:linkbutton id="lnkEdit" runat="server"text="Edit" commandname="Edit"/>
<asp:linkbutton id="lnkdelete" runat="server" text="Edit" commandname="Delete"/>


Code Behind:

if (e.CommandName.equals("Edit"))
{
       int index = System.Convert.ToInt32(e.CommandArgument);
else if(e.commandname.equals("Delete"))
{
         int index = System.Convert.ToInt32(e.CommandArgument);
}


protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            var LinkButton2 = (Button)e.Row.FindControl("btnrate");
            LinkButton2.CommandArgument = e.Row.RowIndex.ToString();
        }
    }
 
Share this answer
 
v4
Comments
_Amy 27-Jul-12 7:46am    
For your interest in this question. +5!
Hi,
Try this:
HTML:(In the item template of your gridview)
ASP.NET
<asp:linkbutton id="lnkEdit" runat="server" text="Edit" commandname="Edit"/>
<asp:linkbutton id="lnkEdit" runat="server" text="Edit" commandname="Delete"/>


Code Behind:

C#
if (e.CommandName=="Edit")
{
    //do edit operation
}
else if (e.CommandName=="Delete")
{
    //do the deletion
}



--Amit
 
Share this answer
 
v2
Comments
[no name] 27-Jul-12 6:36am    
my 5+
vaibhav mahajan 27-Jul-12 6:42am    
pls read the question..!!
_Amy 27-Jul-12 6:37am    
Thank you Mits.
vaibhav mahajan 27-Jul-12 6:41am    
i know this.....bt how to check which row is clicked?...
[no name] 27-Jul-12 6:44am    
int index = System.Convert.ToInt32(e.CommandArgument); you can get the index of particular row clicked.
start from 0.

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