Click here to Skip to main content
15,893,368 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
i am binding data in Gridview control in page load event

how to get a selected column's data in a string from the Gridview control

(ie)It is the primary key of that table,so for every row selected by user there will be a primary key ID column bounded to it..... so i need to get that ID & with this ID, i need to link with the next page of my web application

using Visual Studio 2005 asp.net C# 2.0

below is some of the code what i tried


protected void SubmitButton_Click(object sender, EventArgs e)
{
string bS = Convert.ToString(gridview1.Rows[rowIndex].Cells[2].Text);
}
Posted
Comments
JoCodes 26-Oct-13 15:45pm    
What you meant my next page of ??? you want to get all the selected gridview rows ( ID) as string?
Kumartyr 28-Oct-13 0:58am    
i want to get that ID value to a string variable in a button click present inside the gridview itself

it is a forum, if the user clicks on button present in the side of every particular question that he asked previously he can view the answers & comments given by other users

so for every question posted there is a unique id will be generated behind and will be posted in gridview..see the image attached

if the View Button is clicked the corresponding question's answers and comments should be shown on another gridview in another page with question on the top and replies on the below as like the picture..so for tracking the question ID i need to get the value in string in the VIEW BUTTON click event

i think you understand my question better now

Hi

The follwoing link may help/guide you .

http://forums.asp.net/t/1024293.aspx[^]

Please mark it as answer if it resolves your problem .
 
Share this answer
 
XML
Hi

This is very simple...

in aspx page: suppose you have the Shuttle_Facility_Id is in datakey name....

<pre>
                <asp:GridView ID="gridShuttleAdmin" runat="server" AutoGenerateColumns="false" DataKeyNames="Shuttle_Facility_Id"
                   OnRowDataBound="gridShuttleAdmin_RowDataBound"


</pre>



in code behind : in rowdatabound...you fetch it like this.
C#
protected void gridShuttleAdmin_RowDataBound(object sender, GridViewRowEventArgs e)
{
Label lblshuttlefacilityid = (Label)e.Row.FindControl("lblshuttlefacilityid");
LinkButton lbtn = (LinkButton)e.Row.FindControl("lnkviewID");
//then use that to navigate to next page as below
lbtn.Attributes.Add("onClick", "var sFeatures='dialogHeight: 700px;dialogWidth: 1000px;'; window.showModalDialog('Shuttle_StopDetails.aspx?shuttlefacilityid=" + lblshuttlefacilityid.Text"','',sFeatures);window.document.forms[0].submit();");


 

}
 
Share this answer
 

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