private void PrepareGid() { for (int i = 0; i < hash.Items.Length; i++) { PersonGrid newData; var item = hash.Items[i]; if (item != null) { var keyAndValue = item.First(); newData = new PersonGrid() { Content = (keyAndValue.Value as Person).GetContent(), Index = keyAndValue.Key }; } else { newData = new PersonGrid() { Content = "EMPTY", Index = i }; } data.Add(newData); } dataGrid.ItemsSource = data; }
private void AddNewPersonToItemsSouce(int position, Person person) { data[position] = new PersonGrid() { Content = person.GetContent(), Index = position }; }
private void DeleteFromItemsSource(int position) { data[position] = new PersonGrid() { Index = position, Content = "EMPTY" }; }
protected void BtnDel_Click(object sender, EventArgs e) { Lbl.Text = ""; string selectedValue = ""; for (int i = 0; i < PersonGrid.Rows.Count; i++) { RadioButton rb = (PersonGrid.Rows[i].FindControl("MyRadioButton") as RadioButton); if (rb.Checked == true) { //FName = PersonGrid.Rows[i].Cells[1].Text; //LName = PersonGrid.Rows[i].Cells[2].Text; selectedValue = PersonGrid.Rows[i].Cells[3].Text.Trim(); } } //string selectedValue = Request.Form["MyRadioButton"]; if (selectedValue != "") { //if ((System.Windows.Forms.DialogResult.Yes) == (System.Windows.Forms.MessageBox.Show("Are you sure , you want to Delete the Row", "Delete", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question))) { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sampleConnectionString"].ConnectionString)) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "delete from person where Email='" + selectedValue + "'"; cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); //PersonGrid.DataBind(); Lbl.Text = " 1 Row Deleted Sucessfully"; Lbl.ForeColor = System.Drawing.Color.Green; cmd.CommandText = "select * from person"; PersonGrid.DataSource = cmd.ExecuteReader(); PersonGrid.DataBind(); } } } else { Lbl.Text = "Select a Row to Delete"; Lbl.ForeColor = System.Drawing.Color.Red; } }
protected void PersonGrid_Sorting(object sender, GridViewSortEventArgs e) { Lbl.Text = ""; String columnName = e.SortExpression.ToString(); string order = ""; if (Session["sortexp"] == null) { Session["sortexp"] = columnName; order = " Asc"; } else if (Session["sortexp"].ToString() == columnName) { Session["sortexp"] = null; order = " Desc"; } else { Session["sortexp"] = columnName; order = " Asc"; } using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sampleConnectionString"].ConnectionString)) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "select * from person order by " + columnName + order; cmd.Connection = con; con.Open(); PersonGrid.DataSource = cmd.ExecuteReader(); PersonGrid.DataBind(); } //if (Session["senderRd"] != null) //{ // object senderRd = Session["senderRd"]; // RadioButton rb = (RadioButton)senderRd; // GridViewRow row = (GridViewRow)rb.NamingContainer; // ((RadioButton)row.FindControl("MyRadioButton")).Checked = true; //} }
protected void Page_Load(object sender, EventArgs e) { //if (Session["senderRd"] != null) //{ // object senderRd = Session["senderRd"]; // RadioButton rb = (RadioButton)senderRd; // GridViewRow row = (GridViewRow)rb.NamingContainer; // ((RadioButton)row.FindControl("MyRadioButton")).Checked = true; //} if (!IsPostBack) { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sampleConnectionString"].ConnectionString)) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "select * from person "; cmd.Connection = con; con.Open(); PersonGrid.DataSource = cmd.ExecuteReader(); PersonGrid.DataBind(); //ViewState["sortdr"] = "Asc"; } } }
//Search a person in PersonGrid protected void btnSearch_Click(object sender, EventArgs e) { PersonGrid.DataSource = ""; PersonGrid.DataSource = SDSearchEn; PersonGrid.DataBind(); }