问题描述
<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)
{
LinkButton lnkbtnresult =(LinkButton)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)
{
LinkButton lnkbtnresult =(LinkButton)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.
推荐答案
<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事件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!