Home > DeveloperSection > Forums > How to finds control in gridview
lois waisbrooker
lois waisbrooker

Total Post:70

Posted on    October-06-2014 12:16 AM

 C# ASP.Net  C# 

 1 Reply(s)
 661  View(s)
Rate this:

I have something weird happening, maybe i don't know of something?

I am trying to populate a Drop Down List (in the editItemTemplate) and also, when the Grid View Loads populate a column, with strings instead of the id's that it contains now.

<asp:TemplateField HeaderText="invsId" SortExpression="invsId">


      <asp:DropDownList ID="ddl_invNames" runat="server" AutoPostBack="True" />



      <asp:Label ID="lbl_insLabel" runat="server" Text='<%# Bind("invsId") %>'></asp:Label>



      <asp:DropDownList ID="ddl_invNamesNew" runat="server" AutoPostBack="True" />




protected void gvAdminArticleAdd_RowDataBound(object sender, GridViewRowEventArgs e)


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



                //finding cotrols into the edit rows event              

                if (e.Row.RowState == DataControlRowState.Edit)


                    DropDownList ddlImages = (DropDownList)e.Row.FindControl("ddlImages");

                    ddlImages.DataSource = GetPdfs();



                    DropDownList ddlinvsNames = (DropDownList)e.Row.FindControl("ddl_invNames");

                    ArrayList invList = GetInvestigatorNames();

                    ddlinvsNames.DataSource = invList;




                //finding cotrols into rows

                Label insLabel = (Label)e.Row.FindControl("lbl_insLabel");

                int invsLabelId = int.Parse(insLabel.Text);

                insLabel.Text = connection.GetInvsNameById(invsLabelId);




The problem that I have occur in the RowDataBound event, I can't figure it up what is wrong

//111111 and //22222 are working correctly(if I comment one of them), but not together. how can it be?

if I place them together I am getting an error on this line of code

int invsLabelId = int.Parse(insLabel.Text);

Kamlakar Singh
Kamlakar Singh

Total Post:194

Posted on    October-06-2014 12:20 AM

//111111 and //22222 are working correctly(if I comment one of them), but not together. how can it be?
You do not need those two to work together. Only one will be available at a given time.

if (e.Row.RowState == DataControlRowState.Edit)


           var ddlImages = (DropDownList)e.Row.FindControl("ddlImages");

           var ddlinvsNames = (DropDownList)e.Row.FindControl("ddl_invNames");




           var insLabel = (Label)e.Row.FindControl("lbl_insLabel");


Don't want to miss updates? Please click the below button!

Follow MindStick