title: asp.net GridView RowDataBound smaller code
body: <p>im working on asp.net and c#.</p>
  
  <p>I have a gridview populated from an sql database. I have dropdowlist and textbox controls.</p>
  
  <p>On the RowDataBound event I have values asigned to controls:</p>
  
  <pre><code>protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              Control ctrlgridEstacion = e.Row.FindControl("grid1");
              if (ctrlgridEstacion != null)
              {
                  DropDownList dd = ctrlgridEstacion as DropDownList;
                  SqlDataReader dr;
                  SqlCommand cmd;
                  cmd = new SqlCommand();
                  cmd.Connection = sqlConn;
                  cmd.CommandType = CommandType.StoredProcedure;
                  cmd.CommandText = "sp_load";
                  sqlConn.Open();
                  dr = cmd.ExecuteReader();
                  DataTable dt = new DataTable();
                  dt.Load(dr);
                  dd.DataSource = dt;
                  dd.DataValueField = "code";
                  dd.DataTextField = "code";
                  dd.DataBind();
                  DataRowView rowView = (DataRowView)e.Row.DataItem;
                  string tempDate = rowView["code"].ToString();
                  dd.SelectedIndex = dd.Items.IndexOf(dd.Items.FindByText(tempDate));
                  sqlConn.Close();
              }
  
  Control gridPrefijo = e.Row.FindControl("grid2");
              if (gridPrefijo != null)
              {
                  TextBox dd = gridPrefijo as TextBox;
                  DataTable dt = new DataTable();
                  sqlConn.Open();
                  SqlCommand cmd;
                  cmd = new SqlCommand();
                  cmd.Connection = sqlConn;
                  cmd.CommandType = CommandType.StoredProcedure;
                  cmd.CommandText = "sp_load";
                  SqlDataAdapter sqlDa = new SqlDataAdapter(cmd);
                  sqlDa.Fill(dt);
                  int startIndex;
  
                  if (c1 &lt; 1)
                  {
                      int RC = dt.Rows.Count;
                      int PS = GridView1.PageSize;
                      int PN = GridView1.PageIndex + 1;
                      startIndex = (PN - 1) * PS;
                      int endIndex = Math.Min(RC - 1, startIndex + PS - 1);
                      dri = startIndex;
                  }
  
                  if (dt.Rows.Count &gt; 0)
                  {
                      dd.Text = dt.Rows[dri ]["name"].ToString();
                      c1++;
                  }
                  sqlConn.Close();
              }
  }
  
  }
  </code></pre>
  
  <p>The problem is that I have 15 controls, so adding them to the RowDatabound event is a lot of code.
  How can I make the code smaller?</p>
  
  <p>Thanks..</p>