hi
i have a gridview and in every row i have a button and i want to get the value of cell of that row of which button is clicked.
i cant use rowcomand event. i want to get cell value in buton click event.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Muhammad younasPosted Oct 15, 2012, 4:50 AM
Satyapriya NayakPosted Oct 13, 2012, 8:29 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();
}
}
}
}
Sumit Kumar SinhaPosted Oct 13, 2012, 5:31 AM
.aspx
.aspx.cs
Protected Void Grid1_RowCommand(object sender, GridViewEventArgs e) { if(e.CommandName=="DataCommand") { // Get the value of command argument var value= e.CommandArgument; // Do whatever operation you want. } }