如何在ASP.NET中使用隐藏的界限?
-
12-11-2019 - |
题
我在ASP.NET中使用DataSource绑定GridView,我想拥有一些隐藏的界限,所以我可以在RowDatabound函数中访问这些值。但是,当我在这些绑定场上设置可见=“false”时,值不会设置值,并且始终在rowDatabound函数中为空。
有没有办法这样做?我已经看到一些关于将界端场上的风格设置为隐藏的建议,但这也不适合我。理想情况下,我甚至不希望在GridView中创建的一列,我只需要隐藏这些值,以便我可以访问它们。谢谢!
解决方案
Have you tried using the DataItem
from the GridViewRowEventArgs
passed to your RowDataBound
method?
Like:
protected void MyGridView_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView rowView = (DataRowView)e.Row.DataItem;
// do something with rowView["myHiddenField"]
}
}
其他提示
Odd, How are you doing it? I know I've done this before using:
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("ColumnName")%>'/>
For this i will suggest you to use DataKey.
Pls refer this link http://www.codeproject.com/KB/grid/Data_presentation.aspx
eg:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
DataKeyNames="emp_id,Code">
int EmployeeID = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Values[0]);
int DepartementID = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Values[1]);
in DataRow bound:
((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString();
Geetha
不隶属于 StackOverflow