---
title: "How to finds control in gridview"  
description: "How to finds control in gridview"  
author: "Anonymous User"  
published: 2014-10-06  
updated: 2014-10-06  
canonical: https://www.mindstick.com/forum/2308/how-to-finds-control-in-gridview  
category: "c#"  
tags: ["c#", "asp.net"]  
reading_time: 2 minutes  

---

# How to finds control in gridview

I have something weird happening, maybe i don't know of something?

I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to [populate](https://www.mindstick.com/blog/60/populate-records-in-second-listbox-according-to-the-selection-in-first-list-box) a [Drop Down](https://www.mindstick.com/forum/263/drop-down-list-problem) List (in the editItemTemplate) and also, when the [Grid View](https://www.mindstick.com/forum/477/grid-view) Loads populate a column, with strings instead of the id's that it contains now.

```
<asp:TemplateField HeaderText="invsId" SortExpression="invsId"> <EditItemTemplate>      <asp:DropDownList ID="ddl_invNames" runat="server" AutoPostBack="True" /> </EditItemTemplate> <ItemTemplate>      <asp:Label ID="lbl_insLabel" runat="server" Text='<%# Bind("invsId") %>'></asp:Label> </ItemTemplate> <FooterTemplate>      <asp:DropDownList ID="ddl_invNamesNew" runat="server" AutoPostBack="True" /> </FooterTemplate></asp:TemplateField>
```

**Cdebehind:**

```
protected void gvAdminArticleAdd_RowDataBound(object sender, GridViewRowEventArgs e)        {            if (e.Row.RowType == DataControlRowType.DataRow)            {                //111111                //finding cotrols into the edit rows event                               if (e.Row.RowState == DataControlRowState.Edit)                {                    DropDownList ddlImages = (DropDownList)e.Row.FindControl("ddlImages");                    ddlImages.DataSource = GetPdfs();                    ddlImages.DataBind();                     DropDownList ddlinvsNames = (DropDownList)e.Row.FindControl("ddl_invNames");                    ArrayList invList = GetInvestigatorNames();                    ddlinvsNames.DataSource = invList;                    ddlinvsNames.DataBind();                }                //222222                //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](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) that I have occur in the [RowDataBound](https://www.mindstick.com/forum/12667/gridview-rowdatabound-for-loop-not-working) event, I can't figure it up what is wrong

//111111 and //22222 are working correctly(if I comment [one of them](https://answers.mindstick.com/qa/47593/what-are-the-prevalent-water-proofing-systems-write-a-short-notes-on-any-one-of-them)), but not [together](https://yourviews.mindstick.com/view/80819/live-in-relationship-protecting-the-right-to-live-together). how can it be?

if I place them together I am [getting an error](https://answers.mindstick.com/qa/95244/why-do-you-keep-getting-an-error-message-ox800ccc0b) on this line of code\

```
int invsLabelId = int.Parse(insLabel.Text);
```

## Replies

### Reply by Anonymous User

//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");        }        else        {           var insLabel = (Label)e.Row.FindControl("lbl_insLabel");        }
```


---

Original Source: https://www.mindstick.com/forum/2308/how-to-finds-control-in-gridview

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
