how to select the cell from gridview??

Posted by Hemachandranvperumal under ASP.NET on 11/27/2012 | Points: 10 | Views : 4201 | Status : [Member] | Replies : 5
how to select the cell from grid view?
or
how update n delete the data from gird view?

if i am select the grid-view cell ,that value appear on the same page of text file..
pls anyone help me




Responses

Posted by: Sandhyab on: 11/27/2012 [Member] Starter | Points: 25

Up
0
Down
Refer this article
http://www.dotnetfunda.com/articles/article1619-how-to-perform-edit-update-and-delete-operation-in-gridview.aspx

Thanks & Regards

Hemachandranvperumal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hemachandranvperumal on: 11/27/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks sandhya :-)Thanks for Reply :-)
i need help.
i want learn asp.net
but
i need if i am click the grid view cell ,this value appear on text box and
update and delete separate button .
if i am click update button n click grid view cell value will display on text box and then i can edit and then click the button value will be updated.
same as delete button .



Hemachandranvperumal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jeetu_Choudhary12 on: 11/28/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Hemachandranvperumal,

Please go to below link to for best solution of Edit, Update,cancel and e-mailing:

http://jeetudotnetsql.blogspot.in/2011/10/how-to-editupdate-cancel-and-mail-in.html



Hemachandranvperumal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 11/28/2012 [Member] Starter | Points: 25

Up
0
Down
Hi hemachandra try this code.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Gridtotextbox : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sampcon"].ToString());
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd,cmd1;
SqlDataReader dr ;
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
gridbind();
txtid.Enabled = false;
}
protected void btnsubmit_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd=new SqlCommand("insert into stdrc values('"+txtname.Text+"','"+txtage.Text+"','"+txtaddress.Text+"')",con);
cmd.ExecuteNonQuery();
con.Close();
gridbind();
lblmsg.Text="Data Saved Successfully";
txtaddress.Text = "";
txtage.Text = "";
txtname.Text = "";
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
txtid.Enabled = true;
txtid.Text = GridView1.Rows[e.NewEditIndex].Cells[1].Text.ToString();
txtname.Text = GridView1.Rows[e.NewEditIndex].Cells[2].Text.ToString();
txtage.Text = GridView1.Rows[e.NewEditIndex].Cells[3].Text.ToString();
txtaddress.Text = GridView1.Rows[e.NewEditIndex].Cells[4].Text.ToString();
}
public void gridbind()
{
con.Open();
cmd1 = new SqlCommand("Select * from stdrc", con);
dr = cmd1.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}
protected void btnedit_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("Update stdrc set name='" + txtname.Text + "',age='" + txtage.Text + "',Address='" + txtaddress.Text + "' where ID='"+txtid.Text+"'", con);
cmd.ExecuteNonQuery();
con.Close();
gridbind();
lblmsg.Text = "Data Updated Successfully";
txtaddress.Text = "";
txtage.Text = "";
txtname.Text = "";
txtid.Text = "";
}
protected void btndelete_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("Delete stdrc where Id='" + txtid.Text + "'", con);
cmd.ExecuteNonQuery();
con.Close();
gridbind();
lblmsg.Text = "Data Deleted Successfully";
txtaddress.Text = "";
txtage.Text = "";
txtname.Text = "";
txtid.Text = "";

}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
gridbind();
}
}

Thanks & Regards
Hari

Hemachandranvperumal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 11/28/2012 [Member] Starter | Points: 25

Up
0
Down
If Satisfied with my answer .Please select Mark As Answer

Thanks & Regards
Hari

Hemachandranvperumal, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response