GridView使用Select Command with RowCommand [英] GridView using a Select Command With RowCommand

查看:111
本文介绍了GridView使用Select Command with RowCommand的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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);
        }
    }










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();
            }
        }


    }





如何工作选择选定行上的event和rowcommand事件。



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

推荐答案

+ e.Row.RowIndex);
}
}
" + e.Row.RowIndex); } }










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();
            }
        }


    }





如何工作选择选定行上的event和rowcommand事件。



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


当您为select选择添加命令字段时

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





按钮,命令名称为选择


OR
button with command name "Select"

<columns>
....
<asp:linkbutton id="lbtnServerSelect" runat="server" text="Select" commandname="Select"  />
 </columns>





然后调用Gridview_SelectedIndexChanging事件。你得到新选择的指数

e.NewSelectedIndex;



参考这个



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





或者你也可以像在行中那样捕捉rowCommand中的事件



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

protected void GrdCompany_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Select")
        {
        }
    }


这篇关于GridView使用Select Command with RowCommand的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆