GridView控件----最常用事件

Posted on 2011-07-21 11:39  大瓜佬  阅读(214)  评论(0)    收藏  举报
//控制行绑定数据  RowDataBound事件为控件绑定数据时触发
protected void grdList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
if(e.Row.Cells[5].Text == "0")
{
e.Row.Cells[5].Text == "随便设置";
}
}
}
//Gridview行删除
---添加事件--:onrowcommand="gvwUserList_RowCommand"
---添加行--:<asp:ButtonField ButtonType="Image" ImageUrl="~/Image/Delete.gif" CommandName="Close" ItemStyle-HorizontalAlign="Center" />
后台方法
protected void gvwUserList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Close")
            {
      //获取选择行的DataKeys
                int myID = Convert.ToInt32(gvwUserList.DataKeys[Convert.ToInt32(e.CommandArgument)][0]);
                Meeting.Delete(myID.ToString());
            }
            gvwUserList.DataSource = Meeting.GetMyorderById(Myname);
            gvwUserList.DataBind();
        }

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3