public void BindGrid() { DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(); con = new SqlConnection(ConnectionString()); try { command.Connection = con; command.CommandText = "Select * from " + TableName; da.SelectCommand = command; con.Open(); da.Fill(ds, "Deptdetails"); GvAttendance.DataSource = ds.Tables["Deptdetails"]; GvAttendance.DataBind(); } catch (Exception ex) { throw ex; } finally { con.Close(); command.Dispose(); } }
void PopulateGridviewbyGroup() { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnectionString"].ConnectionString); DataTable dt = new DataTable(); var MID = drpModuleId.SelectedValue; var GNAME = drpGroup.SelectedValue; con.Open(); SqlDataAdapter sda = new SqlDataAdapter("SELECT STUDENTID, STUDENTNAME FROM tblStudent WHERE ModuleCode='" + MID + "' AND \"Group\" ='" + GNAME + "' ", con); sda.Fill(dt); if (dt.Rows.Count > 0) { GvAttendance.DataSource = dt; GvAttendance.DataBind(); } else { dt.Rows.Add(dt.NewRow()); GvAttendance.DataSource = dt; GvAttendance.DataBind(); GvAttendance.Rows[0].Cells.Clear(); GvAttendance.Rows[0].Cells.Add(new TableCell()); GvAttendance.Rows[0].Cells[0].ColumnSpan = dt.Columns.Count; GvAttendance.Rows[0].Cells[0].Text = "No Data Found ..!"; GvAttendance.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataTable dt = CHECKINOUT.GetAllDataRecord(); GvAttendance.DataSource = dt; GvAttendance.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataTable dt = CHECKINOUT.GetAllDataRecord(int.Parse(Session["Sid"].ToString())); GvAttendance.DataSource = dt; GvAttendance.DataBind(); } }
//protected void GvStaff_RowDeleting(object sender, GridViewDeleteEventArgs e) //{ // CHECKINOUT CHECKINOUT.Delete(Convert.ToInt32(GvStaff.DataKeys[e.RowIndex].Value)); // DataTable StaffDT = CHECKINOUT.GetAllActiveData(); // GvStaff.DataSource = StaffDT; // GvStaff.DataBind(); //} //protected void GvStaff_RowEditing(object sender, GridViewEditEventArgs e) //{ // try // { // GvStaff.EditIndex = e.NewEditIndex; // int StaffId = int.Parse((GvStaff.Rows[e.NewEditIndex].FindControl("lbl_SID") as Label).Text); // Response.Redirect("AddStaff.aspx?SId=" + StaffId,false); // } // catch (Exception ex) // { // } //} protected void btnsearch_Click(object sender, EventArgs e) { DataTable checkoutdt = null; try { DataTable dt = CHECKINOUT.GetAllDataRecord(); if (dt != null) { checkoutdt = dt.Select("Name LIKE '%" + txtName.Text.Trim() + "%' AND RollNo like '%" + txtRollNo.Text.Trim() + "%'").CopyToDataTable(); GvAttendance.DataSource = checkoutdt; GvAttendance.DataBind(); } } catch { GvAttendance.DataSource = checkoutdt; GvAttendance.DataBind(); } }