Friends..I have fetched data from database in gridview. And now i want to pass one selected row data into the textboxes...
How can i select the one row on mouse click in gridview and the same time data from selected row should pass into texboxes.. in c# ??
Plz..Help..
if your answer on selectIndexChanged Event I did not find this event in gridview..
Satyapriya NayakPosted Apr 29, 2013, 9:27 AM
using System;
using System.Collections;
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;
namespace Display_selected_records
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
lbl_id.Text = GridView1.SelectedRow.Cells[1].Text;
lbl_name.Text = GridView1.SelectedRow.Cells[2].Text;
lbl_address.Text = GridView1.SelectedRow.Cells[3].Text;
lbl_marks.Text = GridView1.SelectedRow.Cells[4].Text;
lbl_year.Text = GridView1.SelectedRow.Cells[5].Text;
}
void bindgrid()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from student";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "student");
GridView1.DataSource = ds;
GridView1.DataMember = "student";
GridView1.DataBind();
con.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid();
}
}
}
}