Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void GrdCompany_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
            e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";

            e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.PeopleGridView, "Select$" + e.Row.RowIndex);
        }
    }



C#
protected void GrdCompany_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "EditCompany")
        {
            Response.Redirect("~/Company.aspx?CmpId=" + e.CommandArgument.ToString());
        }

        if (e.CommandName == "DeleteCompany")
        {
            int AffectRow = Cmp.Delete_Company(e.CommandArgument.ToString());
            if (AffectRow > 0)
            {
                Fill_Grid();
            }
        }


    }


how to work select event and rowcommand event on selected row.
Posted

1 solution

When you add command field for select
C#
 <columns>
...
<asp:commandfield showselectbutton="true"  />
 </columns>

OR
button with command name "Select"
C#
<columns>
....
<asp:linkbutton id="lbtnServerSelect" runat="server" text="Select" commandname="Select"  />
 </columns>


then Gridview_SelectedIndexChanging event get called. You get newly selected index by
e.NewSelectedIndex;

Refer this

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedindexchanging%28v=vs.110%29.aspx


Or you can catch event in rowCommand also as you did
C#
protected void GrdCompany_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Select")
        {
        }
    }
 
Share this answer
 
v3

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