如何从Gridview控件中获取字符串中的选定列的数据 [英] how to get a selected column's data in a string from the Gridview control

查看:65
本文介绍了如何从Gridview控件中获取字符串中的选定列的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面加载事件中绑定Gridview控件中的数据



如何从Gridview控件中获取字符串中所选列的数据



(即)它是该表的主键,因此对于用户选择的每一行,都会有一个主键ID列,因此我需要得到它那个ID和这个ID,我需要链接到我的网络应用程序的下一页



使用Visual Studio 2005 asp.net C#2.0



下面是我试过的一些代码





protected void SubmitButton_Click(object sender, EventArgs e)

{

string bS = Convert.ToString(gridview1.Rows [rowIndex] .Cells [2] .Text);

}

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);
}

推荐答案

您好



以下链接可以帮助/指导您。



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



如果能解决问题,请将其标记为答案。
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 .


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>







代码背后:在rowdatabound中...你这样取得它。




in code behind : in rowdatabound...you fetch it like this.

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();");


 

}


这篇关于如何从Gridview控件中获取字符串中的选定列的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆