Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
In my Grid, I have one imgbutton and linkbutton and Usercontrol bind grid data. I am using RowCOmmand
Problems
1. Unable to get the UserControl Id
2. Unable to get the Usercontrol methods.

Can any one give me some suggestion how to solve this.

What I have tried:

HI,
 <pre> <asp:GridView runat="server" ID="grdNotfiy" OnRowCommand="grdNotfiy_RowCommand" OnRowDataBound="grdNotfiy_RowDataBound" GridLines="None" Width="100%"
                AutoGenerateColumns="false" DataKeyNames="KeyIdUnique,ReferenceKey">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <table style="padding: 5px;">
                                <tr style="border: none;">
                                    <td style="border: none;">
                                        <asp:Label ID="lblAlertTypeId" runat="server" Text='<%#Eval("AlertTypeId")%>' Visible="false"></asp:Label>
                                        <asp:HiddenField ID="hdnKeyId" runat="server" Value='<%# Eval("KeyIdUnique") %>' />
                                        <a href="div<%# Eval("PageId")%>" id="imgCollapse">
                                            <asp:ImageButton runat="server" ID="imgNotify" CommandName="NotifyValidate"
                                                ImageUrl='<%# Eval("NotifyImage")%>' Height="30" Width="30" CssClass="mt-1" />
                                        </a>
                                    </td>
                                    <td style="border: none; width: 200px; padding: 10px;">
                                        <a href="div<%# Eval("KeyIdUnique")%>" id="expndPopup">
                                            <asp:LinkButton runat="server" ForeColor="Brown" ID="lnkNotify"
                                                Text='<%# Eval("AlertNotes") %>'
                                                CommandName="Select">
                                            </asp:LinkButton>
                                        </a>
                                    </td>
                                </tr>
                                <div class="dvDetails">
                                    <tr class="detail" id="myDetail" runat="server" style="overflow: hidden; border-color: #fff; display: none;">
                                        <td id="Td1" colspan="3" runat="server">
                                            <h1>hello</h1>
                                            <Kolme:LeaveAprrve ID="usrLveArpvls" runat="server" LeaveApprve='<%# Eval("KeyIdUnique") %>'/>
                                        </td>
                                    </tr>
                                </div>
                                <tr>
                                    <td></td>
                                    <td style="border: none;">
                                        <asp:LinkButton ID="lnkSave" CssClass="mt-2 align-content-center"
                                            runat="server" Style="text-align: center;" Width="30" Height="22" ToolTip="Approve"
                                            CommandName="LApprove" CommandArgument='<%#((GridViewRow) Container).RowIndex %>'><span><img src="../../Images/accept_button.png" width="20" height="20" 
                                          style="margin-top:-10px;" alt="Save" /></span>
                                        </asp:LinkButton>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2" style="border: 1px solid groove">
                                        <hr />
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>


protected void grdNotfiy_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow clickedRow = ((LinkButton)e.CommandSource).NamingContainer as GridViewRow;
string cmndName = e.CommandName;
if (cmndName == "Select")
{
var lveRqstId = grdNotfiy.DataKeys[clickedRow.RowIndex].Values["KeyIdUnique"];
var refkey = grdNotfiy.DataKeys[clickedRow.RowIndex].Values["ReferenceKey"];
if (refkey != null)
{
var json = refkey.ToString();
DashBoardAlert key = JsonConvert.DeserializeObject<dashboardalert>(json);
string empid = key.Employeeid.ToString();

if (!string.IsNullOrEmpty(empid))
{
Session["NotifyEmpId"] = empid;
}
}
if (lveRqstId != null && lveRqstId != "")
{
Session["LveReqstId"] = lveRqstId;
}


Control userControl =(clickedRow.FindControl("usrLveArpvls") as Control);
if (userControl != null)
{
GridView nestdGrid = (userControl.FindControl("grdLeaves") as GridView);

}
}
}

UserControl code

public List<approveleaverequestlistview> GetData(string leaverequestid)
{

return lstApproveLeaves;

}
}
Posted
Updated 17-Jul-20 23:36pm

1 solution

Finally, I got the solution. If any needs use this.

Conditions:

1. Don't use usercontrol instead of use iframes in gridview
2. Create a new page in that inherits Usercontrol from Page_load
3. Pass querystring then Get Usercontrol methods.

Solution:

<div class="dvDetails">
                                   <tr class="detail" id="myDetail" runat="server" style="overflow: hidden; border-color: #fff; display: none;">
                                       <td id="Td1" colspan="3" runat="server">
                                           <asp:UpdatePanel runat="server">
                                               <ContentTemplate>
                                                   <iframe id="dsplyLeaveApvls"  runat="server" style="height: 390px; margin-left: -25px; border: none" src="DisplayLeaveAprovals.aspx?lverqstId=<%# Eval("KeyIdUnique")%>">" ></iframe>
                                               </ContentTemplate>
                                               <Triggers>
                                                   <asp:AsyncPostBackTrigger ControlID="lnkNotify" EventName="Click" />
                                               </Triggers>
                                           </asp:UpdatePanel>

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


New Page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DisplayLeaveAprovals.aspx.cs" Inherits="Kolme.Portal.Pages.Notification.DisplayLeaveAprovals" %>

<%@ Register Src="~/UserControls/LeaveApproval.ascx" TagName="LeaveAprrve" TagPrefix="Kolme" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="~/Scripts/jquery-3.0.0.js"></script>
    <script src="~//Scripts/bootstrap.js"></script>
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
    <%-- <link href="https://use.fontawesome.com/releases/v5.0.4/css/all.css" rel="stylesheet" />--%>
    <link href=".~//Styles/PageStyles.css" rel="stylesheet" />
    <link href="~/Styles/MasterStyles.css" rel="stylesheet" />
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
        </div>
        <div class="container">
            <Kolme:LeaveAprrve ID="usrLveArpvls" runat="server" />
        </div>
    </form>
</body>
</html>

public partial class DisplayLeaveAprovals : System.Web.UI.Page
   {
       protected void Page_Load(object sender, EventArgs e)
       {
           if (!IsPostBack)
           {
               if (!string.IsNullOrEmpty("lverqstId"))
               {
                   usrLveArpvls.leaveRequstId = Request.QueryString["lverqstId"];
               }
           }

       }
   }


Finally Usercontrol Code:

public string leaveRequstId { get; set; }

       #endregion
       protected void Page_Load(object sender, EventArgs e)
       {
           if (Session["CurrentUser"] != null && Session["CurrentUser"] != "")
           {
               objCurrentUser = (CurrentUser)Session["CurrentUser"];
           }
           if (!IsPostBack)
           {
               if (string.IsNullOrEmpty(txtName.Text))
               {
                   Session["LCmnts"] = txtName.Text;
               }
               else
               {
                   Session["LCmnts"] = txtName.Text;
               }
               BindData();
           }
       }

       private void BindData()
       {
           grdLeaves.DataSource = GetData(leaveRequstId);
           grdLeaves.DataBind();
       }

Don't forget create property for parameter id

Thanks & Regards,
V.prudhvi
Bye
 
Share this answer
 

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