Click here to Skip to main content
14,877,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a master gridview In that two link buttons. If I click on Linkbutton1 it should display data in another gridview.IF I click on linkbutton2 in it should display data another gridview. It's just like 2 childgirdview for single master gridview.Can anyone help me to How to do this through example coding?



Thanks in advance!!!

What I have tried:

My Design Page Here:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LoanAccountDetails.aspx.cs"
    Inherits="LoanAccountDetails" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Banksoft Internet Banking</title>
    <link href="Css/Banksoftstyles.css" rel="stylesheet" type="text/css" />

    <script src="js/BanksoftScript.js" type="text/javascript"></script>

    <link href="Css/style.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">
        function preventBack() { window.history.forward(); }
        setTimeout("preventBack()", 0);
        window.onunload = function() { null };
    </script>
  <%--Added by shruthi N--%> 
   <script type="text/javascript">
       function showNestedGridView(obj) {
           var NestedGridView = document.getElementById(obj);
           var imageID = document.getElementById('image' + obj);

           if (NestedGridView.style.display == "none") {
               NestedGridView.style.display = "inline";
               // imageID.src = "img/minus.png";
           }
           else {
               NestedGridView.style.display = "none";
               //imageID.src = "img/plus.png";
           }
       }
</script>
    <%--Added by janardhan, the following functions disable the View Source and Ctrl+U--%>

    <script type="text/javascript" language="javascript">
        $(function() { $(this).bind("contextmenu", function(e) { e.preventDefault(); }); }); 
    </script>

    <script type="text/javascript" language="javascript">
        document.onkeydown = function(e) {
            if (e.ctrlKey &&
            (e.keyCode === 85)) {
                return false;
            }
        };
    </script>

   <%-- <script type="text/javascript" language="javascript">
        function fnDispJointAcntDets() {
            var settings = 'width=640,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=No,resizable=No,top=100%,left=350%,position: fixed';            
            url = 'Help/JointAcntDetails.aspx';
            popup = window.open(url, '', settings, target = '_blank');
            popup.focus();
        }
        function fnDispSuretyDets() {
            var settings = 'width=640,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=No,top=100%,left=350%,position: fixed';
            url = 'Help/SuretyorGuarantor.aspx';
            popup = window.open(url, '', settings, target = '_blank');
            popup.focus();
        }
    </script>
--%>
</head>
<body style="overflow-x:hidden;overflow-y:hidden;">
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>       
            <%--<div>--%>
           <div class="main">             
                <%--<div class="box">--%>
                    <h5>
                        LOAN ACCOUNT DETAILS</h5>
                    <center>
                        <br />
                        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  DataKeyNames="AccountNumber"
                            OnRowCommand="GridView1_RowCommand" 
                            onselectedindexchanged="GridView1_SelectedIndexChanged" 
                            onrowdatabound="GridView1_RowDataBound">
                            <Columns>
                                <asp:TemplateField HeaderText="ACCOUNT NUMBER">
                                    <ItemTemplate>
                                        <asp:LinkButton Style="text-decoration: underline;" ID="Linkbtnacno" runat="server"
                                            EnableTheming="True" Text='<%# Eval("AccountNumber") %>' CommandName="SelectAcNo"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                 <asp:TemplateField HeaderText="SCHEME NAME">
                                    <ItemTemplate>
                                        <asp:Label ID="lblSchemeName" Style="text-align: justify;" runat="server" Text='<%# Eval("SchemeName") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="DATE OF ACCOUNT OPEN">
                                    <ItemTemplate>
                                        <asp:Label ID="lblAcntOpen" Style="text-align: justify;" runat="server" Text='<%# Eval("DateOfActOpening") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="ACCOUNT TYPE">
                                    <ItemTemplate>
                                        <asp:Label ID="lblAcntType" Style="text-align: justify;" runat="server" Text='<%# Eval("AccountType") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="JOINT HOLDER">
                                    <ItemTemplate>
                                        <%--<asp:LinkButton ID="lbtnJointAcntDetsc" runat="server" Style="display: block; text-align: center;
                                            text-decoration: underline" EnableTheming="True" CommandName="CmdJointAcntDets">Click here</asp:LinkButton>--%>                                            
                                              
                                            <%--  <a href="javascript:showNestedGridView('accountNumber-<%# Eval("AccountNumber") %>');">
                                    <img id="imageaccountNumber-<%# Eval("AccountNumber") %>" text="ClickHere"
                                    alt="ClickHere" border="0"/>--%>
                                              <asp:LinkButton ID="lbtnJointAcntDetsc" runat="server" Style="display: block; text-align: center;
                                        text-decoration: underline" EnableTheming="True" CommandName="CmdJointAcntDets">Click here</asp:LinkButton>
                                        <%--<asp:Label ID="lblJntHolder" Style="text-align: left;" runat="server" Text='<%# Eval("JointHolderName") %>'></asp:Label>--%>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="SURETY DETAILS">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lbtnNomineeDets" runat="server" Style="display: block; text-align: center;
                                            text-decoration: underline" EnableTheming="True" CommandName="CmdSuretyDets">Click here</asp:LinkButton>
                                        <%--<asp:Label ID="lblNomDetails" Style="text-align: left;" runat="server" Text='<%# Eval("NomineeDetails") %>'></asp:Label>--%>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="DATE OF EXPAIRY">
                                    <ItemTemplate>
                                        <asp:Label ID="lblDtofMaturity" Style="text-align: left;" runat="server" Text='<%# Eval("ExpairyDate") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="ROI">
                                    <ItemTemplate>
                                        <asp:Label ID="lblROI" Style="text-align: center;" runat="server" Text='<%# Eval("RateOfInterest") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Sanctioned Amount">
                                    <ItemTemplate>
                                        <asp:Label ID="lblDepAmount" Style="text-align: left;" runat="server" Text='<%# Eval("SanctionAmount") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Closing Balance">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lbtnforBlnc" runat="server" Style="display: block; text-align: right;padding:0px;width:80px;
                                            text-decoration: underline" EnableTheming="True" CommandName="ClickforBlnc">Click Here for balance</asp:LinkButton>
                                        <asp:LinkButton ID="lbtnClosing" runat="server" Style="display: block; text-align: right;
                                            text-decoration: underline" EnableTheming="True" Text='<%# Eval("ClosingBalance") %>'
                                            CommandName="SelectClosingBal" Visible="false"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <%--<asp:TemplateField HeaderText="CLOSING BALANCE">
                            <ItemTemplate>
                                <asp:LinkButton ID="lbtnforBlnc" runat="server" Style="display: block; text-align: right;
                                    text-decoration: underline" EnableTheming="True" CommandName="ClickforBlnc">Click Here for balance</asp:LinkButton>
                                <asp:LinkButton ID="lbtnClosing" runat="server" Style="display: block; text-align: right;
                                    text-decoration: underline" EnableTheming="True" Text='<%# Eval("ClosingBalance") %>'
                                    CommandName="SelectClosingBal" Visible="false"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>--%>
                         <asp:TemplateField>
                            <ItemTemplate>
                                <tr>
                                    <td colspan="100%">
                                        <%--<div id='<%# Eval("AccountNumber")%>' style="display:none">--%>
                                        <div id="accountNumber-<%# Eval("AccountNumber") %>" 
                                            style="display:none;position:relative;left:25px;" >
                                        <%--<div ID="NestedDiv" runat="server">--%>
                            <%--<asp:TemplateField HeaderText="CLOSING BALANCE">
                            <ItemTemplate>
                                <asp:LinkButton ID="lbtnforBlnc" runat="server" Style="display: block; text-align: right;
                                    text-decoration: underline" EnableTheming="True" CommandName="ClickforBlnc">Click Here for balance</asp:LinkButton>
                                <asp:LinkButton ID="lbtnClosing" runat="server" Style="display: block; text-align: right;
                                    text-decoration: underline" EnableTheming="True" Text='<%# Eval("ClosingBalance") %>'
                                    CommandName="SelectClosingBal" Visible="false"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>--%>
                        <asp:GridView ID="GridView2" runat="server"  DataKeyNames="JointCustCode" AutoGenerateColumns="False"
                            Width="80%" style="overflow-y:none;" 
                            onselectedindexchanged="GridView1_SelectedIndexChanged">
                            <Columns>
                                <asp:TemplateField HeaderText="Joint Customer Code">
                                    <ItemTemplate>
                                        <asp:Label ID="lblAcntOpen" Style="text-align: justify;" runat="server" 
                                            Text='<%# Eval("JointCustCode") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Desgnation Of Joint Operator">
                                    <ItemTemplate>
                                        <asp:Label ID="lblAcntType" Style="text-align: justify;" runat="server" 
                                            Text='<%# Eval("DesgnOfJointOper") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Relation With Account Holder">
                                    <ItemTemplate>
                                        <asp:Label ID="lblDtofMaturity" Style="text-align: left;" runat="server" 
                                            Text='<%# Eval("RelationWithAccHold") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                        </div>
                            </td>
                            </tr>
                            
                                   <tr>
                                    <td colspan="100%">
                                        <%--<div id='<%# Eval("AccountNumber")%>' style="display:none">--%>
                                        <div id="accountNumber1" 
                                            style="display:none;position:relative;left:25px;" >
                        <asp:GridView ID="GridView3" runat="server" DataKeyNames="SurityCustCode" AutoGenerateColumns="False" Width="80%">
                            <Columns>
                                <asp:TemplateField HeaderText="Surety Customer Code">
                                    <ItemTemplate>
                                        <asp:Label ID="lblAcntOpen" Style="text-align: justify;" runat="server" Text='<%# Eval("SurityCustCode") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Surety Guarantor">
                                    <ItemTemplate>
                                        <asp:Label ID="lblAcntType" Style="text-align: justify;" runat="server" Text='<%# Eval("SurityGuarantor") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Description">
                                    <ItemTemplate>
                                        <asp:Label ID="lblDtofMaturity" Style="text-align: left;" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                           </div>
                            </td>
                            </tr>
                            </ItemTemplate>
                        </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                        <br />
                        <asp:LinkButton ID="lnkNoAcntstoDisp" runat="server" Style="color: Red;font-size:large;font-family:Times New Roman"  Text="Sorry, You have no Loan Accounts"></asp:LinkButton>
                    </center>
                <%--</div>--%>
                <div>
                    <center>
                        <asp:Label ID="lblerrormsg" Style="color: Red" runat="server"></asp:Label>
                        <input id="hdnAcntNo" type="hidden" runat="server" />
                    </center>
                </div>
               </div>
            <%--</div>--%>
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>




My Code Behind asp.net c.s here:


public partial class LoanAccountDetails : System.Web.UI.Page
{
Bclass objb = null;
private ArrayList ArrayParamList = null;

protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{

try
{
//Added by janardhan to restrict the user to copy and paste the url in Address Bar
string strPreviousPage = "";
if (Request.UrlReferrer != null)
{
strPreviousPage = Request.UrlReferrer.Segments[Request.UrlReferrer.Segments.Length - 1];
}
if (strPreviousPage == "")
{
Response.Redirect("~/ErrorPages/RestrictURLAccess.aspx");
}
//Ends here by janardhan

if (!string.IsNullOrEmpty(SessionHandler.ConnString))
{
//DataTable dt = new DataTable();
//dt = SessionHandler.dsCustomerDetails.Tables[0].Clone(); /*Clone method copies the table schema*/
//foreach (DataRow drw in SessionHandler.dsCustomerDetails.Tables[0].Rows)
//{
// if (Convert.ToString(drw["Categorycode"]) == "LON")
// {
// dt.ImportRow(drw);
// }
//}
//GridView1.DataSource = dt;
//GridView1.DataBind();
////SetPageDesign();

string AcNo = SessionHandler.RegAccountNumber;
DataSet ds = new DataSet();
objb = new Bclass();
ArrayParamList = new ArrayList();
ArrayParamList.Add(AcNo.Trim());
ArrayParamList.Add("GetCustLoanAcntDetails");
ds = objb.GetAccountInformation(ArrayParamList);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();

GridView1.Visible = true;
lnkNoAcntstoDisp.Visible = false;
}
else
{
GridView1.Visible = false;
lnkNoAcntstoDisp.Visible = true;
}


}
}
catch (Exception ex)
{
lblerrormsg.Text = ex.Message;
lblerrormsg.ForeColor = Color.Red;
}
}
}

protected void SetPageDesign()
{

/*CssStyle background color from CodeBehind*/
/*Step1: set ID and runat="Server" to the body tag so that it can be referenced to the Code Behind
Step2: Next, to add a CSS property to this body tag on codebehind, e.g.*/
if (SessionHandler.BankCode.Equals("BNK00062")) /*BNK00062-Taqwa Credit Cooperative Society Ltd*/
{

}
else if (SessionHandler.BankCode.Equals("BNK00015")) /*BNK00015-Manvi Pattana Sa Bank Ni*/
{
/*MPSS*/

}
else if (SessionHandler.BankCode.Equals("BNK00019")) /*BNK00019-SRI VASAVAMBA CO-OPERATIVE BANK LTD*/
{
/*SVCBHNP*/

}
else if (SessionHandler.BankCode.Equals("BNK00009")) /*BNK00009-The Accountant Generals Office Employees Co-operative Bank Limited*/
{
/*AGS*/


}
else if (SessionHandler.BankCode.Equals("BNK00045")) /*BNK00045-RESERVE BANK EMPLOYEES CO-OPERATIVE BANK LTD.*/
{
//mybody.Attributes.CssStyle.Add("background", "linear-gradient(red, yello);");
/*RBE*/

}
else if (SessionHandler.BankCode.Equals("BNK00022")) /*BNK00022-Shri Shivayogi Murughendra Swami Urban Co- Op Bank Ltd.*/
{
/*SSMS*/


}
else if (SessionHandler.BankCode.Equals("BNK00041")) /*BNK00041-Guru raghavendra*/
{

}
else
{
// pagebody.Attributes.CssStyle.Add("background", "linear-gradient(#00339a, Gray);");

}
}

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{

GridViewRow gvr = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
int rowIndex = gvr.RowIndex;
LinkButton HyperAcNo = (LinkButton)GridView1.Rows[rowIndex].Cells[0].FindControl("Linkbtnacno");
Cache["tmpAcntNum"] = HyperAcNo.Text.Trim();

if (e.CommandName == "SelectAcNo")
{
Response.Redirect("AccountInformation.aspx", true);
}
else if (e.CommandName == "SelectClosingBal")
{
Response.Redirect("ClosingBalance.aspx", true);
}
else if (e.CommandName == "ClickforBlnc") /*Option to show the closing balance onclick of Linkbutton*/
{
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
int rIndex = row.RowIndex;
GridView1.Rows[rIndex].Cells[GridView1.Rows[rIndex].Cells.Count - 1].FindControl("lbtnforBlnc").Visible = false;
GridView1.Rows[rIndex].Cells[GridView1.Rows[rIndex].Cells.Count - 1].FindControl("lbtnClosing").Visible = true;
}
else if (e.CommandName == "CmdJointAcntDets")
{
//ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(Page), "OnClientClicking", "fnDispJointAcntDets(" + hdnAcntNo.Value + ");", true);
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(Page), "OnClientClicking", "fnDispJointAcntDets();", true);
}
else if (e.CommandName == "CmdSuretyDets")
{
//ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(Page), "OnClientClicking", "fnDispSuretyDets(" + hdnAcntNo.Value + ");", true);
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(Page), "OnClientClicking", "fnDispSuretyDets();", true);
}
}
catch (Exception ex)
{
lblerrormsg.Text = ex.Message;
lblerrormsg.ForeColor = Color.Red;
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

{

}



protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//Image btnAlert = (Image)e.Row.FindControl("lnkDisplayPopUp_Click");



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

//string ass = e.Row.Cells[4].Text;

//TableCell statusCell = e.Row.Cells[4];
//if (statusCell.Text == "")
//{
// //if (e.Row.Cells[4].Text.Contains(""))
//{

//LinkButton lb = e.Row.FindControl("Linkbtnacno") as LinkButton;
//ScriptManager.GetCurrent(this).RegisterPostBackControl(lb);
//string tmpAcntNum = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
//GridView gv2 = e.Row.FindControl("GridView2") as GridView;

string tmpAcntNum = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
try
{

#region Commented
if (!string.IsNullOrEmpty(Convert.ToString("tmpAcntNum")))
{
GridView gv2 = (GridView)e.Row.FindControl("GridView2");
DataSet ds = new DataSet();
objb = new Bclass();
ArrayList ArrayParamList = new ArrayList();
ArrayParamList.Add(tmpAcntNum.Trim());
ArrayParamList.Add("GetCustJointAcntDetails");
ds = objb.GetAccountInformation(ArrayParamList);

if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
gv2.DataSource = ds.Tables[0];
gv2.DataBind();

}
else
{
gv2.Visible = true;


}
}
#endregion
}
catch (Exception ex)
{
lblerrormsg.Text = ex.Message;
lblerrormsg.ForeColor = Color.Red;
lblerrormsg.Visible = true;
}
finally
{
Cache.Remove("AcntNum");
}

}
}


}
Posted

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