Click here to Skip to main content
Sign Up to vote bad
good
See more: ASP.NET
<pre lang="c#">
Parent Grid row bound Event:

    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 17 Jan '13 - 7:37
OPees1.5K
Edited 17 Jan '13 - 17:05

Comments
OPees - 17 Jan '13 - 13:39
Thanks in advance..!!
richcb - 17 Jan '13 - 15:24
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
  Permalink  
Comments
OPees - 18 Jan '13 - 0:28
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" > <asp:TemplateField ControlStyle-BorderStyle="None" ControlStyle-Width="5%"> <img id="imagepnlid-<%# Eval("Dept_ID") %>" alt="Click to show/hide Department" border="0" src="../plus.png" /> <%----%> <asp:BoundField ItemStyle-Width="" DataField="DepartmentName" HeaderText="Department" ControlStyle-Width="95%"> <asp:TemplateField> <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" > <asp:TemplateField HeaderText="Task ID"> <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>

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 423
1 OriginalGriff 291
2 Mayur_Panchal 153
3 Mohammed Hameed 145
4 Dave Kreskowiak 125
0 Sergey Alexandrovich Kryukov 8,146
1 OriginalGriff 6,236
2 CPallini 3,482
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid