Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my code. I want to find gridview ("grdVDetails") inside anchor tag ("lnkVoucher") in another gridview ("grdVoucher"). But it returns null. Please help.

ASP.NET
<asp:GridView ID="grdVoucher" runat="server" AutoGenerateColumns="False" OnRowCommand="grdVoucher_RowCommand"
        OnRowDataBound="grdVoucher_RowDataBound" Width="100%">
        <Columns>
            <asp:TemplateField HeaderText="Voucher No">
                <ItemTemplate>
                    <a id="lnkVoucher" href="java<!-- no -->script:" runat="server">
                        <div id="HidePODetail">
                            <asp:GridView ID="grdVDetails" runat="server" AutoGenerateColumns="False" OnRowDataBound="grdVDetails_RowDataBound"
                                Width="100%">
                                <Columns>
                                    <asp:TemplateField HeaderText="Head Code">
                                        <ItemStyle HorizontalAlign="Center" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Head Name"></asp:TemplateField>
                                    <asp:TemplateField HeaderText="Debit"></asp:TemplateField>
                                    <asp:TemplateField HeaderText="Credit"></asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                        </div>
                    </a>
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
        </Columns>
    </asp:GridView>



C# code is:

C#
protected void grdVoucher_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            sp_Acc_ReadAll_JournalVoucherResult entry = e.Row.DataItem as sp_Acc_ReadAll_JournalVoucherResult;


            HtmlAnchor lnkVoucher = e.Row.FindControl("lnkVoucher") as HtmlAnchor;
            lnkVoucher.InnerText = entry.VoucherNo;

            GridView grdVDetails = e.Row.FindControl("grdVDetails") as GridView;
            List<Acc_Transation> list = CAccTransation.GetAllTransationByVoucherCode(entry.VoucherNo);
            grdVDetails.DataSource = list;
            grdVDetails.DataBind();
        }
    }
Posted
Updated 3-Feb-15 19:59pm
v4

 
Share this answer
 
Oh I solved it myself. I just use another tag to bind data innertext on it and make free the innertext of anchor tag. Then I easily get the gridview.

C#
protected void grdVoucher_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            sp_Acc_ReadAll_JournalVoucherResult entry = e.Row.DataItem as sp_Acc_ReadAll_JournalVoucherResult;


            HtmlAnchor lnkVoucher = e.Row.FindControl("lnkVoucher") as HtmlAnchor;
            //lnkVoucher.InnerText = entry.VoucherNo;            
            HtmlGenericControl spVoucher = e.Row.FindControl("spVoucher") as HtmlGenericControl;
            spVoucher.InnerText = entry.VoucherNo;

            e.Row.Cells[1].Text = entry.Debit.ToString();
            e.Row.Cells[2].Text = entry.Credit.ToString();
            e.Row.Cells[3].Text = Convert.ToDateTime(entry.Date).ToShortDateString();
LinkButton lnkEdit = e.Row.FindControl("lnkEdit") as LinkButton;
            lnkEdit.CommandArgument = entry.VoucherNo;

            LinkButton lnkDelete = e.Row.FindControl("lnkDelete") as LinkButton;
            lnkDelete.CommandArgument = entry.VoucherNo;
            

            GridView grdVDetails = e.Row.FindControl("grdVDetails") as GridView;
            List<Acc_Transation> list = CAccTransation.GetAllTransationByVoucherCode(entry.VoucherNo);
            grdVDetails.DataSource = list;
            grdVDetails.DataBind();
        }
    }
 
Share this answer
 
v2

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