Guest User

Untitled

a guest
Jan 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  2. {
  3. if (e.Row.RowType == DataControlRowType.DataRow)
  4. {
  5. Control ctrlgridEstacion = e.Row.FindControl("grid1");
  6. if (ctrlgridEstacion != null)
  7. {
  8. DropDownList dd = ctrlgridEstacion as DropDownList;
  9. SqlDataReader dr;
  10. SqlCommand cmd;
  11. cmd = new SqlCommand();
  12. cmd.Connection = sqlConn;
  13. cmd.CommandType = CommandType.StoredProcedure;
  14. cmd.CommandText = "sp_load";
  15. sqlConn.Open();
  16. dr = cmd.ExecuteReader();
  17. DataTable dt = new DataTable();
  18. dt.Load(dr);
  19. dd.DataSource = dt;
  20. dd.DataValueField = "code";
  21. dd.DataTextField = "code";
  22. dd.DataBind();
  23. DataRowView rowView = (DataRowView)e.Row.DataItem;
  24. string tempDate = rowView["code"].ToString();
  25. dd.SelectedIndex = dd.Items.IndexOf(dd.Items.FindByText(tempDate));
  26. sqlConn.Close();
  27. }
  28.  
  29. Control gridPrefijo = e.Row.FindControl("grid2");
  30. if (gridPrefijo != null)
  31. {
  32. TextBox dd = gridPrefijo as TextBox;
  33. DataTable dt = new DataTable();
  34. sqlConn.Open();
  35. SqlCommand cmd;
  36. cmd = new SqlCommand();
  37. cmd.Connection = sqlConn;
  38. cmd.CommandType = CommandType.StoredProcedure;
  39. cmd.CommandText = "sp_load";
  40. SqlDataAdapter sqlDa = new SqlDataAdapter(cmd);
  41. sqlDa.Fill(dt);
  42. int startIndex;
  43.  
  44. if (c1 < 1)
  45. {
  46. int RC = dt.Rows.Count;
  47. int PS = GridView1.PageSize;
  48. int PN = GridView1.PageIndex + 1;
  49. startIndex = (PN - 1) * PS;
  50. int endIndex = Math.Min(RC - 1, startIndex + PS - 1);
  51. dri = startIndex;
  52. }
  53.  
  54. if (dt.Rows.Count > 0)
  55. {
  56. dd.Text = dt.Rows[dri ]["name"].ToString();
  57. c1++;
  58. }
  59. sqlConn.Close();
  60. }
  61. }
  62.  
  63. }
Add Comment
Please, Sign In to add comment