How to finds control in gridview

Total Post:70

C#  ASP.Net 
 1342  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);

  1. Post:194

    Re: How to finds control in gridview

    //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");

      Modified On Apr-05-2018 06:39:26 AM