Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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
Updated 7-Oct-12 22:14pm
v2

1 solution

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.

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


and then in row command method add below code.

C#
protected void RowCommand( object sender, GridViewCommandEventArgs e ) 
{     
    int rowIndex = Convert.ToInt32( e.CommandArgument );  
    //Here you can write your code to display.
} 
 
Share this answer
 
v2
Comments
M@anish 8-Oct-12 4:54am    
i know but i dont know how to do this
Mohd. Mukhtar 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900