如何对选择行事件进行grdiview?在源页面上,我添加了
OnSelectedIndexChanged="grdTanks_OnSelectRow"
在后面的代码中,我把函数
protected void grdTanks_OnSelectRow(Object sender, GridViewCommandEventArgs e)
{
}
当我尝试这样做时,我得到没有重载grdTanks_OnSelectRow匹配委托'System.EventHandler'
如果我将GridViewComandEventArgs更改为EventArgs,那么它将不允许我这样做
if (e.CommandName == "Select")
有人知道如何为gridview做OnSelectRow事件吗?感谢
我还添加了这段代码:
protected void grdTanks_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex != -1)
{
e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.background='#3260a0';;this.style.color='white'";
if (e.Row.RowIndex % 2 == 1)
{
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';this.style.background='white';this.style.color='black'";
}
else
{
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';this.style.background='#bEc8bE';this.style.color='black'";
}
e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.grdTanks, "Select$" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "CargoTankID")));
}
}
}
答案 0 :(得分:3)
你可以试试这个:
在page_load中,输入
grdTanks.SelectedIndexChanged +=
并按两次标签。 Visual Studio会自动为您生成处理程序。第二个参数是EventArgs
答案 1 :(得分:1)
我认为你必须改变
protected void grdTanks_OnSelectRow(Object sender, GridViewCommandEventArgs e)
要
protected void grdTanks_SelectedIndexChanged(Object sender, GridViewCommandEventArgs e)
在您的代码中
答案 2 :(得分:1)
我不确定你想在这个事件处理程序中做什么。您已经在处理select事件,我认为,无需再次检查(e.CommandName == "Select").
(MSDN:当单击行的“选择”按钮时会引发SelectedIndexChanged事件)。
该错误表示事件没有重载,您必须使用EventArgs
参数。
protected void grdTanks_OnSelectRow(Object sender, EventArgs e)
{
// May be you want like..
// Get the currently selected row using the SelectedRow property.
GridViewRow row = YourGridViewID.SelectedRow;
}