Get SelectedDataKey in RowDataBound
问题 this code is returning a NullReferenceException since the SelectedDataKey is not selected yet. How can I check if the the DataKey is selected or not.. protected void grdRoles_RowDataBound1(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { CheckBox chk = (CheckBox)e.Row.FindControl("chkRole"); int rolecode = Convert.ToInt32(this.grdRoles.DataKeys[e.Row.RowIndex].Value); BusinessLayer.Customers checkRole = new BusinessLayer.Customers(); bool check =