我如何从<asp:BoundField DataField="DateStart"访问数据。我有一条IF语句,我想看看数据是>还是<,而不是DataField中的数据。
我曾经用过rows(0).findControl,但现在不能用了。
If today > item.FindControl("btnSelect") And today < item.FindControl("btnSelect") Then如果可能的话
发布于 2014-01-22 00:18:26
不能在BoundField%s上使用FindControl,只能对TemplateFields使用。您需要使用单元的Text property
Dim text = grid.Rows(index).Cells(index).Text ' the cell-index is the column-index '您需要将其解析为DateTime/Date
Dim dateStart = Date.Parse(text)
If Date.Today > dateStart.Date ...但是,如果您使用RowDataBound,则可以访问原始的DataItem。但是,我需要了解更多,才能向您展示一个示例。
发布于 2014-01-22 00:33:58
在GridView的定义中,添加
<asp:GridView .... DataKeyNames="ItemID" ...>您还需要使用OnRowDataBound,而不是OnDataBound
<asp:GridView .... DataKeyNames="ItemID" ... OnRowDataBound="GridView_RowDataBound">然后在你的后台代码中,类似这样
protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
int ItemId = Int32.Parse(YourGridView.DataKeys[e.Row.RowIndex].Values[0].ToString());
}
}如果要查找多个值,请将DataKeyNames设置为
DataKeyNames="ID,Name,COde,Value and so on"
https://stackoverflow.com/questions/21263470
复制相似问题