Click here to Skip to main content
15,885,720 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
<pre lang="c#">
Parent Grid row bound Event:
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") 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.
Posted
Updated 17-Jan-13 17:05pm
v2
Comments
OPees 17-Jan-13 13:39pm    
Thanks in advance..!!
Richard C Bishop 17-Jan-13 15:24pm    
You have not explained anything or even asked a question. This is just a code dump. Use the "Improve Question" widget and formulate a specific question regarding your goal.

1 solution

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>

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
 
Share this answer
 
v2
Comments
OPees 18-Jan-13 0:28am    
my Grid is like this
<asp:GridView ID="gvDepartment" runat="server" AutoGenerateColumns="False" BorderColor="Transparent"
Width="100%" BorderWidth="0px" BorderStyle="None" DataKeyNames="Dept_ID" OnRowDataBound="OnRowDataBound" Height="266px" onrowcommand="gvDepartment_RowCommand1" >
<columns>
<asp:TemplateField ControlStyle-BorderStyle="None" ControlStyle-Width="5%">
<itemtemplate>

<img id="imagepnlid-<%# Eval("Dept_ID") %>" alt="Click to show/hide Department" border="0"
src="../plus.png" />


<%--<controlstyle borderstyle="None">--%><controlstyle borderstyle="None"
="" width="5%">

<asp:BoundField ItemStyle-Width="" DataField="DepartmentName" HeaderText="Department"
ControlStyle-Width="95%">
<controlstyle width="95%">

<asp:TemplateField>
<itemtemplate>
<tr>
<td colspan="100%">
<div id="pnlid-<%# Eval("Dept_ID") %>" style="display: none; position: relative; left: 25px;">

<asp:GridView ID="gvRunning" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid" OnRowDataBound="OnRowDataBound1" onrowcommand="gvDepartment_RowCommand" >
<columns>
<asp:TemplateField HeaderText="Task ID">
<itemtemplate>
<asp:LinkButton ID="requestID3" runat="server" CommandName="COUNT_REQUEST_ID" CommandArgument="gvRuning" OnClick="requestID3_Click"
Text='<%# Eval("Task_ID")%>'>
<asp1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panel1" TargetControlID="requestID3"
CancelControlID="btnClose" BackgroundCssClass="modalBackground">



<asp:BoundField DataField="Task_Name" HeaderText="Task Name" SortExpression="Task_Name" />
<asp:BoundField DataField="Discription" HeaderText="Description" SortExpression="Discription" />
<asp:BoundField DataField="Star_Date" HeaderText="Start Date" SortExpression="Star_Date" />
<asp:BoundField DataField="End_Date" HeaderText="End Date" SortExpression="End_Date" />
<asp:BoundField DataField="Delay_Date" HeaderText="Delay Date" SortExpression="Delay_Date" />


</div>
</td>
</tr>

<controlstyle borderstyle="None" width="0%">


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900