Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static DataTable Datatable()
- {
- ubicacion_componentes componenteLocations = new ubicacion_componentes();
- DataTable dt = new DataTable();
- dt.Columns.Add("ubicacion_componente_id");
- dt.Columns.Add("armario");
- dt.Columns.Add("cajon");
- foreach (var cmp in componenteLocations.ubicaction_componentes)
- {
- var row = dt.NewRow();
- row["ubicacion_componente_id"] = cmp.ubicacion_componente_id;
- row["armario"] = cmp.armario;
- row["cajon"] = cmp.cajon;
- dt.Rows.Add(row);
- }
- return dt;
- }
- protected void BindGridList(string sortExp, string sortDir)
- {
- DataTable dt = Datatable();
- DataView dv = new DataView(dt);
- dv = dt.DefaultView;
- if (sortExp != string.Empty)
- {
- dv.Sort = string.Format("{0} {1}", sortExp, sortDir);
- }
- gvLocation.DataSource = dv;
- gvLocation.DataBind();
- if (dt.Rows.Count > 0)
- {
- gvLocation.DataSource = dt;
- gvLocation.DataBind();
- }
- else
- {
- dt.Rows.Add(dt.NewRow());
- gvLocation.DataSource = dt;
- gvLocation.DataBind();
- gvLocation.Rows[0].Cells.Clear();
- gvLocation.Rows[0].Cells.Add(new TableCell());
- gvLocation.Rows[0].Cells[0].ColumnSpan = dt.Columns.Count;
- gvLocation.Rows[0].Cells[0].Text = "datos no encontrados";
- gvLocation.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
- }
- }
- public string sortOrder
- {
- get
- {
- if (ViewState["sortOrder"].ToString() == "desc")
- {
- ViewState["sortOrder"] = "asc";
- }
- else
- {
- ViewState["sortOrder"] = "desc";
- }
- return ViewState["sortOrder"].ToString();
- }
- set
- {
- ViewState["sortOrder"] = value;
- }
- }
- protected void gvLocation_Sorting(object sender, GridViewSortEventArgs e)
- {
- BindGridList(e.SortExpression, sortOrder);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement