Asp.net datalist control
-
Hello friends, please I need your help in this stuff. I have a datalist control on my asp.net webpage with the following buttons(Add, Remove, Cancel). I'm able to code the the button add using OnItemCommand. But, I'm unable to code the one of Remove and Cancel to call the sub procedures I wrote in vb code behind. Also, I would like a specific record to be removed from the datalist control when the remove button is click. Please help. Thanks in advance!
-
Hello friends, please I need your help in this stuff. I have a datalist control on my asp.net webpage with the following buttons(Add, Remove, Cancel). I'm able to code the the button add using OnItemCommand. But, I'm unable to code the one of Remove and Cancel to call the sub procedures I wrote in vb code behind. Also, I would like a specific record to be removed from the datalist control when the remove button is click. Please help. Thanks in advance!
I here mention a complete code below in Data List Add,Remove and Update.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;public partial class mytesting : System.Web.UI.Page
{protected void Page\_Load(object sender, EventArgs e) { if (!IsPostBack) { GetData(); } } private void GetData() { SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=jogi;Integrated Security=True"); try { con.Open(); SqlCommand cmd = new SqlCommand("select \* from jogi2", con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); DataList1.DataSource = ds.Tables\[0\]; DataList1.DataBind(); } finally { con.Close(); } } protected void DataList1\_EditCommand(object source, DataListCommandEventArgs e) { DataList1.EditItemIndex = e.Item.ItemIndex; GetData(); } protected void DataList1\_CancelCommand(object source, DataListCommandEventArgs e) { DataList1.EditItemIndex = -1; GetData(); } protected void DataList1\_UpdateCommand(object source, DataListCommandEventArgs e) { String id = ((Label)e.Item.FindControl("Label3")).Text; TextBox role = (TextBox)e.Item.FindControl("TextBox1"); TextBox password = (TextBox)e.Item.FindControl("TextBox3"); SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=jogi;Integrated Security=True"); con.Open(); SqlCommand cmd = new SqlCommand("update jogi2 set role='" + role.Text + "',password='" + password.Text + "'where id ='" + id + "'", con); int i = cmd.ExecuteNonQuery(); if (i > 0) { Label4.Text = "Recard Updated successfully...."; GetData(); } } protected void DataList1\_DeleteCommand(object source, DataListCommandEventArgs e) { String id = ((Label)e.Item.FindControl("Label1")).Text; SqlConnection con = new SqlConne
-
I here mention a complete code below in Data List Add,Remove and Update.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;public partial class mytesting : System.Web.UI.Page
{protected void Page\_Load(object sender, EventArgs e) { if (!IsPostBack) { GetData(); } } private void GetData() { SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=jogi;Integrated Security=True"); try { con.Open(); SqlCommand cmd = new SqlCommand("select \* from jogi2", con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); DataList1.DataSource = ds.Tables\[0\]; DataList1.DataBind(); } finally { con.Close(); } } protected void DataList1\_EditCommand(object source, DataListCommandEventArgs e) { DataList1.EditItemIndex = e.Item.ItemIndex; GetData(); } protected void DataList1\_CancelCommand(object source, DataListCommandEventArgs e) { DataList1.EditItemIndex = -1; GetData(); } protected void DataList1\_UpdateCommand(object source, DataListCommandEventArgs e) { String id = ((Label)e.Item.FindControl("Label3")).Text; TextBox role = (TextBox)e.Item.FindControl("TextBox1"); TextBox password = (TextBox)e.Item.FindControl("TextBox3"); SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=jogi;Integrated Security=True"); con.Open(); SqlCommand cmd = new SqlCommand("update jogi2 set role='" + role.Text + "',password='" + password.Text + "'where id ='" + id + "'", con); int i = cmd.ExecuteNonQuery(); if (i > 0) { Label4.Text = "Recard Updated successfully...."; GetData(); } } protected void DataList1\_DeleteCommand(object source, DataListCommandEventArgs e) { String id = ((Label)e.Item.FindControl("Label1")).Text; SqlConnection con = new SqlConne
Waooo, what a marvellous post! Banger, thank you very much. You post was easy to understand. Thanks alot...