Oct 28, 2009
Grid view Edit using check boxes
set the property DataKeyNames ="id" for gridview and use above java script for selecting all check boxes at a time
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MySql.Data.MySqlClient;
using System.IO;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
MySqlConnection con = new MySqlConnection("data source=localhost;database=test;user id=root;password=root");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
MySqlDataAdapter da = new MySqlDataAdapter("select * from student", con);
DataSet ds = new DataSet();
da.Fill(ds, "st");
gvdevice.DataSource = ds;
gvdevice.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
StringBuilder IDs = new StringBuilder();
int count = gvdevice.Rows.Count;
for (int i = 0; i < count; i++)
{
CheckBox chkSelect = gvdevice.Rows[i].FindControl("chkSelect") as CheckBox;
if (chkSelect.Checked)
{
object id=gvdevice.DataKeys[i].Value;
int idr = int.Parse(id.ToString());
string abcd = "abcd";
string s = "update student set name='" + abcd + "' where id='" + idr + "'";
MySqlCommand cmd=new MySqlCommand(s,con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment