.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

How to get the value of a Hidding column in a Gridview using C#

Posted By:Syed Shakeer Hussain       Posted Date: September 08, 2009    Points: 25    Category: ASP.NET    URL: http://www.dotnetspark.com  
 

 How to Hide a column in a Gridview  :-

    To Hide a column we have to use a hidden filed as follows:

eg:

   Above i am using a Value attribute to retrive a data from a 'ProductId column.

   Here i am displaying 4 columns values in a Gridview.
   In a Gridview i am using 'select 'link,when a user selects a row in Grid that selected Row id value have to retrive.

   How to create a' select 'link column in Gridview :-

 'Select' Link  can be build by using 'CommandField' as follows:






































SelectCommand="SELECT * FROM [Products]">

  Next Select your Gridview Events.Double click on SelectedIndexChanged Event and write the Below code  in .asp.cs page:

protected void Gridivew1_SelectedIndexChanged(object sender, EventArgs e)
{
string strValue = ((HiddenField)Gridivew1.SelectedRow.Cells[1].FindControl("HiddenField1")).Value;
string strValue2 = ((Label)Gridivew1.SelectedRow.Cells[1].FindControl("lblProductName1")).Text ;


Response.Write("Product Id=" + strValue + "product=" + strValue2);



}

   Thanks for reading my article!

    Syed Shakeer Hussain

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend