0

I able to find DetailsView inside LoginView1

DetailsView DetailsView1 = (DetailsView)LoginView1.FindControl("DetailsView1");

Above statement works... But I fail to find label inside DetailsView

Label id = (Label)DetailsView1.FindControl("id");

the above statement return me null

here my aspx code

<asp:LoginView ID="LoginView1" runat="server">
        <LoggedInTemplate>
            <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
                DataKeyNames="FeeID" DataSourceID="SqlDataSource1" Height="50px" 
                Visible="False" Width="100%">
                <Fields>
                    <asp:TemplateField HeaderText="FeeID" InsertVisible="False" 
                        SortExpression="FeeID">
                        <EditItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("FeeID")%>'></asp:Label>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="id" runat="server" Text='<%# Bind("FeeID") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
        </Fields>
                    </asp:DetailsView>
        </LoggedInTemplate>
            <AnonymousTemplate>
            Access Denied.
            </AnonymousTemplate>
        </asp:LoginView>

Can anyone help me?

khheng
  • 137
  • 1
  • 9

2 Answers2

0

After DataBinding the control, you'd use:

DetailsView1.Rows[0].Cells[0].FindControl("id")

Try , it might work or change the row or cell index accordingly.

akshaykumar6
  • 1,967
  • 3
  • 16
  • 31
0

First,

DetailsView view = (DetailsView)LoginView1.Rows[0].FindControl("DetailsView1");

Then,

Label id = (Label)view.rows[0].FindControl("id");