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

Total Post:70

Points:494
Posted on    October-06-2014 12:16 AM

 C# ASP.Net  C# 
Ratings:


 1 Reply(s)
 683  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">

 <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 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

Points:1396
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");

        }

        else

        {

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

        }

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

Follow MindStick