Hi,
I have a gridview with username as the linkbutton in a template field. when user clicks on the linkbutton i want the username value which is a linkbutton. I do not want to use the row command 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.
Satyapriya NayakPosted Nov 28, 2011, 8:42 AM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
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
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
DataSet ds = new DataSet();
SqlCommand com;
SqlConnection con;
SqlDataAdapter sqlda;
string str;
string str1;
protected void Page_Load(object sender, EventArgs e)
{
binddata();
}
void binddata()
{
con = new SqlConnection(connStr);
con.Open();
str = "select * from employee";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "employee");
GridView1.DataSource = ds;
GridView1.DataMember = "employee";
GridView1.DataBind();
con.Close();
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
GridView1.SelectedIndex = Convert.ToInt32(e.NewSelectedIndex);
str1 = GridView1.SelectedDataKey.Value.ToString();
Label1.Text = "You have selected employee Name:" + str1;
binddata();
}
}
Thanks
If this post helps you mark it as answer