Click here to Skip to main content
15,944,390 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please help me to find the control in detail view.

Label compname = DetailsView1.Rows[1].Cells[0].FindControl("complbl");

 i am getting error us

"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"

D K N T H 28-Nov-11 23:03pm    
are you sure that line causes an error? 28-Nov-11 23:21pm    
yes hi i will attach my aspx could you please chk am i doing any thing wrong
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px"
Width="554px" AutoGenerateRows="False" BackColor="White" Visible="false"
BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4"
GridLines="Horizontal" >
<footerstyle backcolor="White" forecolor="#333333">
<rowstyle backcolor="White" forecolor="#333333">
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<asp:TemplateField HeaderText="Company Name">
<asp:Label ID="complbl" runat = "server" text='<%# Eval("CompName")%>'>

<asp:TemplateField HeaderText="Company Address">
<asp:Label ID="addlbl" runat="server" Visible="true" text='<%# Eval("CompAdd")%>'>

<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
<editrowstyle backcolor="#339966" font-bold="True" forecolor="White">

1 solution

Label compname = (Label)DetailsView1.Rows[1].Celles[0].FindControl("complbl");

that is the right syntax, but the error is pointing to a different source. Try doing this one:

if(DetailsView1.Rows.Count != 0)
   Label compname = (Label)DetailsView1.Rows[1].Celles[0].FindControl("complbl");

Share this answer
Comments 28-Nov-11 23:24pm    
Hi Eduard thanks for your reply
i tried the same DetailsView1.Rows.Count != 0 becoming false
i have given aspx code above could you please correct where it is going wrong

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