C# 如何从隐藏列中获取值?
下面是我的代码,它可以完美地处理可见列。但是,我需要能够获取某些不可见列的值:C# 如何从隐藏列中获取值?,c#,asp.net,gridview,C#,Asp.net,Gridview,下面是我的代码,它可以完美地处理可见列。但是,我需要能够获取某些不可见列的值: protected void btnSearchForSchedules_Click(object sender, EventArgs e) { var ds = new DataSet(); var schedulesTable = new DataTable(); foreach (GridViewRow gvr in gv
protected void btnSearchForSchedules_Click(object sender, EventArgs e)
{
var ds = new DataSet();
var schedulesTable = new DataTable();
foreach (GridViewRow gvr in gvShows.Rows)
{
if (gvr.RowType == DataControlRowType.DataRow)
{
if (((CheckBox) gvr.FindControl("cbSelect")).Checked)
{
string baseURL = WebConfigurationManager.AppSettings["SchedulesAPI"];
string dataSource = gvr.Cells[1].Text;
string showId = gvr.Cells[2].Text; //this column is hidden so I'm getting a NULL here
string episodeId = gvr.Cells[4].Text;
string callingURL = baseURL + "?datasource=" + dataSource + "&showid=" + showId;
if (episodeId != " ")
{
callingURL = callingURL + "&episodeId=" + episodeId;
}
schedulesTable = Transporter.GetDataTableFromAPI(callingURL);
ds.Tables.Add(schedulesTable);
}
}
}
谁能解释一下我是怎么做到的:
字符串showId=gvr.Cells[2]。文本
如果列不可见?当您想要获取隐藏列值时,可以在aspx页面中为该GridView指定
DataKeyNames
属性
<asp:GridView ID="GridView1" runat="server" DataKeyNames="column1" ...>
我看到了另一个问题,但我不知道如何在我的代码中使用它。这会有帮助吗?
string showId = (string) GridView1.DataKeys[2].Value.ToString();