public void SelectKeyValue(Guid id) { // find index of current key in grid int index = -1; DataTable dt = (DataSource as DataView).Table; string collumnName = DataKeyNames.FirstOrDefault(); for (int i = 0; i < dt.Rows.Count; i++) { Guid key = (Guid)dt.Rows[i][collumnName]; if (key == id) { index = i; } } // find in which page is current key PageIndex = index / PageSize; OnPageIndexChanging(new GridViewPageEventArgs(PageIndex)); for (int i = 0; i < DataKeys.Count; i++) { if ((Guid)DataKeys[i].Value == id) { SelectedIndex = i; break; } } OnSelectedIndexChanged(new EventArgs()); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { ctlMasterGridView.DataKeyNames = DataKeyNames.Split(','); ctlMasterGridView.DataCountAndBind(); ctlUpdatePanelGridView.Update(); } }
protected override void OnRowDataBound(GridViewRowEventArgs e) { base.OnRowDataBound(e); if (e.Row.RowType != DataControlRowType.DataRow) { return; } if (!ShowCheckBox || dataSourceSelected == null) { return; } if (UData.Contains((DataTable)dataSourceSelected, DataKeyNames.GetValue(0).ToString(), UWeb.ToString(e, DataKeyNames.GetValue(0).ToString()))) { CheckBox chk = e.Row.FindControl("chk") as CheckBox; chk.Checked = true; } }