如何处理子视图内的链接按钮的Click事件。 [英] how to Handle Click event of link button which is inside child gridview.

查看:64
本文介绍了如何处理子视图内的链接按钮的Click事件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<pre lang="c#">

父网格行绑定事件:




protected void OnRowDataBound(object sender,GridViewRowEventArgs e)

{

if(e.Row.RowType == DataControlRowType.DataRow)

{

string DepartmentID = gvDepartment.DataKeys [e.Row.RowIndex] .Value.ToString();

GridView gvCompleated = e.Row.FindControl(gvCompleated )作为GridView;

GridView gvRunning = e.Row.FindControl(gvRunning)作为GridView;

TaskGateway employeeGateObj = new TaskGateway();

gvRunning.DataSource = employeeGateObj.GetTaskTable(DepartmentID);

gvRunning.DataBind();

gvCompleated.DataSource = employeeGateObj.GetPendingTaskTable(DepartmentID) );

gvCompleated.DataBind();

foreach(gvCompleated.Rows中的GridViewRow gr)

{

if(gr.RowType == DataControlRowType.DataRow)

{

LinkBut​​ton lnkbtnresult =(LinkBut​​ton)gr.Cells [0] .FindControl(requestID3);

if(lnkbtnresult!= null)

{

lnkbtnresult.Click + = new System.EventHandler(requestID3_Click);

}

}



}

foreach(gvRunning.Rows中的GridViewRow gr)

{

if(gr.RowType == DataControlRowType.DataRow)

{

LinkBut​​ton lnkbtnresult =(LinkBut​​ton)gr.Cells [0] .FindControl(requestID3);

if(lnkbtnresult!= null)

{

lnkbtnresult.Click + = new System.EventHandler(requestID3_Click);

}

}

}

}



上面的代码我做了在父网格行绑定,在父网格我有两个子网格视图一个是gvcompleted而另一个是gvrunning,我有每个子网格视图上的链接按钮,但我无法处理链接按钮的点击事件,即使我试图对子网格rowbound和rowcommand事件做但是它们不起作用。


protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string DepartmentID = gvDepartment.DataKeys[e.Row.RowIndex].Value.ToString();
GridView gvCompleated = e.Row.FindControl("gvCompleated") as GridView;
GridView gvRunning = e.Row.FindControl("gvRunning") as GridView;
TaskGateway employeeGateObj = new TaskGateway();
gvRunning.DataSource = employeeGateObj.GetTaskTable(DepartmentID);
gvRunning.DataBind();
gvCompleated.DataSource = employeeGateObj.GetPendingTaskTable(DepartmentID);
gvCompleated.DataBind();
foreach (GridViewRow gr in gvCompleated.Rows)
{
if (gr.RowType == DataControlRowType.DataRow)
{
LinkButton lnkbtnresult = (LinkButton)gr.Cells[0].FindControl("requestID3");
if (lnkbtnresult != null)
{
lnkbtnresult.Click += new System.EventHandler(requestID3_Click);
}
}

}
foreach (GridViewRow gr in gvRunning.Rows)
{
if (gr.RowType == DataControlRowType.DataRow)
{
LinkButton lnkbtnresult = (LinkButton)gr.Cells[0].FindControl("requestID3");
if (lnkbtnresult != null)
{
lnkbtnresult.Click += new System.EventHandler(requestID3_Click);
}
}
}
}

The above code i did on the parent grid row bound, in the parent grid i have two child grid view one is gvcompleted and another is gvrunning,and i have link button on each child grid view but i am not able to handle click event of link button, even i tried to do on the child grid rowbound and rowcommand event but they are not working.

推荐答案

如果你想得到链接按钮的点击事件那么就有简单的代码,用户RowCommad网格视图事件:

请参阅:

假设gridview类似于

If you want to get the click event of link button then there is simple code, user RowCommad event of grid view:
see:
Assume gridview is like
<asp:gridview id="grvTest" runat="server" xmlns:asp="#unknown">
  <asp:templatefield>
    <itemtemplate>
      <asp:linkbutton id="lnk" runat="server" text="Test" commandname="TestCommand" />
    </itemtemplate>
  </asp:templatefield>
</asp:gridview>



和你的aspx.cs文件强调RowCommad之类的事件:


and your aspx.cs file contense the event RowCommad like :

Protected Void grvTest_RowCommand(object sender, GridViewCommandEventArgs e) 
{
    If(e.CommandName == "TestCommand")
    {
      ///Do your code here
    }
}





如果对您有帮助,请接受解决方案



if helpful to you, accept the solution


这篇关于如何处理子视图内的链接按钮的Click事件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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