Click here to Skip to main content
11,433,997 members (55,630 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP:NET
I retrieve data in grid view in grid we have a link control if we click on that link
the link show total information on regarding this link but i have a problem when i click on that link data is show but in grid view multiple data link is there how can i show information different different value on it i did so task please have a look
SqlConnection con;
        con = new SqlConnection("Data Source=RESTON-PC;Initial Catalog=Easy2Connect;Integrated Security=True");
        con.Open();
        string s = "Select AdTitle,DescriptionofAd,TeachingSubject,Preferlocation,Classwise,Address,MobileNo,Logo  from HomeTuitionInformation where ADType = 'Offer'";
        SqlCommand cmd = new SqlCommand(s, con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
 

        //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        //{
        //    TextBox1.Text += ds.Tables[0].Rows[i]["AdTitle"].ToString() + "  , ";
        //}
       // string i = ds.Tables[0].Rows[0]["AdTitle"].ToString();
      //  string  var1 = Convert.ToString( ds.Tables[0].Rows[0].ToString()); //ds.Tables[0].Rows[0]["AdTitle"]);
        
        Session["Ad"] = 
        GridView1.DataSource = ds;
        GridView1.DataBind();
data is show but value is fix when how can i change the value on that link
what ever link is click by user the value is show regarding this link

please guide me what should i do
Posted 7-Oct-12 22:40pm
M@anish1.3K
Edited 7-Oct-12 23:14pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,

Use the command name and command argument object avail into the link button and give the value some identity into the commnad name or argument.

And access the value into the on click event method, Use that value to redirect or fetch the data for that identity to display.

Hope this will help you.

Use below code.

<asp:LinkButton Id="linkButtonABC" runat="server" CommandName="Display" Text="Display" CommandArgument='<%# Eval("id") %>' />

and then in row command method add below code.

protected void RowCommand( object sender, GridViewCommandEventArgs e ) 
{     
    int rowIndex = Convert.ToInt32( e.CommandArgument );  
    //Here you can write your code to display.
} 
  Permalink  
v2
Comments
M@anish at 8-Oct-12 4:54am
   
i know but i dont know how to do this
Mohd. Mukhtar at 8-Oct-12 5:01am
   
For this you need to bind CommandName value in HTML.
For more assistant you should copy your gridview HTML code here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.150428.2 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100