What shabarinadh.vempati is trying to say is -
Add 'OnRowCommand' event to your gridview like-
<asp:gridview id="gvap" runat="server" autogeneratecolumns="false" onrowcommand="gvap_RowCommand" xmlns:asp="#unknown"></asp:gridview>
and add commandname property to your linkbutton
and then on its eventhandler in code behind file do something like -
protected void gvap_RowCommand(objectsender,GridViewCommandEventArgs e)
{
if (e.CommandName == "EditMe")
{
GridViewRow grow = (GridViewRow)(((linkbutton)e.CommandSource).NamingContainer);
hdn.Value = grow.Cells[1].Text;
}
do something like this try to access the grid's row values using any state management technique..
One more thing write the whole sql interation and databinding in a function and call it on page load with a (!ispostback)like -
public void populategrid()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=(local); Initial Catalog=123; User Id=sa; Password=123; Integrated Security=false";
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select course_name , start_date , end_date, timings, amount from courses where start_date>=GETDATE()";
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
gvap.DataSource = ds;
gvap.DataBind();
}
and then on page load
if(!ispostback)
{
populategrid();
}
hope this helps!