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 System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//bind();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("Id");
dt.Columns.Add("Name");
dt.Columns.Add("City");
ds.Tables.Add(dt);
if (ds.Tables[0].Rows.Count == 0)
{
DataRow dr = dt.NewRow();
dr[0] = "1";
dr[1] = "mithilesh";
dr[2] = "varanasi";
dt.Rows.Add(dr);
//ds.Tables.Add(dt);
}
GridView2.DataSource = dt;
GridView2.DataBind();
}
}
public void bind()
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "data source=RANJAN-PC;initial catalog=mithilesh;uid=sa;pwd=chandan;integrated security=false";
cn.Open();
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand("select * from emp", cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
//GridView1.DataSource = dt;
//GridView1.DataBind();
//Repeater1.DataSource = dt;
//Repeater1.DataBind();
//DataList1.DataSource = dt;
//DataList1.DataBind();
//DetailsView1.DataSource = dt;
//DetailsView1.DataBind();
//FormView1.DataSource = dt;
//FormView1.DataBind();
//ListView1.DataSource = dt;
//ListView1.DataBind();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
//SqlConnection cn = new SqlConnection();
//cn.ConnectionString = "data source=RANJAN-PC;initial catalog=mithilesh;uid=sa;pwd=chandan;integrated security=false";
//cn.Open();
//int i=Convert.ToInt32(GridView1.SelectedIndex);
//int id = Convert.ToInt32(GridView1.Rows[i].Cells[0].Text);
//string a = GridView1.Rows[i].Cells[1].Text;
//string b = GridView1.Rows[i].Cells[2].Text;
//string c = GridView1.Rows[i].Cells[3].Text;
//TextBox1.Text = id.ToString();
//TextBox2.Text = a.ToString();
//TextBox3.Text = b.ToString();
//TextBox4.Text = c.ToString();
//bind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
//GridView1.EditIndex = e.NewEditIndex;
//bind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//SqlConnection cn = new SqlConnection();
//cn.ConnectionString = "data source=RANJAN-PC;initial catalog=mithilesh;uid=sa;pwd=chandan;integrated security=false";
//cn.Open();
//int id = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[0].Text);
//SqlCommand cmd = new SqlCommand("delete from emp where eid='" + id + "'",cn);
//cmd.ExecuteNonQuery();
//bind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
//GridView1.EditIndex = -1;
//bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
// SqlConnection cn = new SqlConnection();
// cn.ConnectionString = "data source=RANJAN-PC;initial catalog=mithilesh;uid=sa;pwd=chandan;integrated security=false";
// cn.Open();
// Int32 id = Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text);
// string a = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
// string b = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
//string c = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
// SqlCommand cm = new SqlCommand("update emp set enmae='" + a + "',ecity='" + b + "',econtact='" + c + "' where eid='" + id + "'", cn);
// cm.ExecuteNonQuery();
// GridView1.EditIndex = -1;
// bind();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
}
protected void TextBox3_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//SqlConnection cn = new SqlConnection();
//cn.ConnectionString = "data source=RANJAN-PC;initial catalog=mithilesh;uid=sa;pwd=chandan;integrated security=false";
//cn.Open();
//SqlCommand cm = new SqlCommand("update emp set enmae='" +TextBox2.Text+ "',ecity='" + TextBox3.Text+ "',econtact='" +TextBox4.Text + "' where eid='" + Convert.ToInt32(TextBox1.Text) + "'", cn);
//cm.ExecuteNonQuery();
//bind();
//TextBox1.Text = "";
//TextBox2.Text = "";
//TextBox3.Text = "";
//TextBox4.Text = "";
foreach (GridViewRow ch in GridView1.Rows)
{
CheckBox c = (CheckBox)GridView1.Rows[ch.RowIndex+1].FindControl("CheckBox1");
if(c.Checked==true)
{
int id = Convert.ToInt32(GridView1.Rows[ch.RowIndex+1].Cells[0].Text);
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "data source=RANJAN-PC;initial catalog=mithilesh;uid=sa;pwd=chandan;integrated security=false";
cn.Open();
SqlCommand cm = new SqlCommand("delete from emp where eid='" + id + "'", cn);
cm.ExecuteNonQuery();
bind();
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
//SqlConnection cn = new SqlConnection();
//cn.ConnectionString = "data source=RANJAN-PC;initial catalog=mithilesh;uid=sa;pwd=chandan;integrated security=false";
//cn.Open();
//SqlCommand cm = new SqlCommand("insert into emp values('" + Convert.ToInt32(TextBox1.Text) + "','" + TextBox2.Text.ToString() + "','" + TextBox3.Text.ToString() + "','" + TextBox4.Text.ToString() + "')", cn);
//cm.ExecuteNonQuery();
//bind();
//TextBox1.Text = "";
//TextBox2.Text = "";
//TextBox3.Text = "";
//TextBox4.Text = "";//int i = 0;
//if (e.CommandName.Equals("delete"))
//{
int i=0;
foreach (RepeaterItem ri in Repeater1.Items)
{
CheckBox c = (CheckBox)ri.FindControl("chk1");
if (c.Checked == true)
{
i = Convert.ToInt32(c);
}
}
Response.Write("total chk is" + i.ToString());
//}
}
protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
{
DetailsView1.PageIndex = e.NewPageIndex;
bind();
}
protected void DetailsView1_PageIndexChanged(object sender, EventArgs e)
{
}
protected void FormView1_PageIndexChanging(object sender, FormViewPageEventArgs e)
{
FormView1.PageIndex = e.NewPageIndex;
bind();
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
//CheckBox chk = (CheckBox)e.Item.FindControl("chk");
//if (chk.Checked == true)
//{
// Response.Write("check");
//}
}
protected void Button3_Command(object sender, CommandEventArgs e)
{
//int i = 0;
//if (e.CommandName.Equals("delete"))
//{
// foreach (RepeaterItem ri in Repeater1.Items)
// {
// CheckBox c = (CheckBox)ite
// if (c.Checked == true)
// {
// i = i + 1;
// }
// }
// Response.Redirect("total chk is" + i.ToString());
//}
}
}