문제

I am binding a GridView using a DataSource in asp.net, and i would like to have some hidden BoundFields so I can access those values in my RowDataBound Function. However, when I set Visible="False" on these BoundFields the values do not get set and are always blank in the RowDataBound function.

Is there a way to do this? I've seen some suggestions of setting the style on the BoundField to hidden but this did not work for me either. Ideally I don't even want a column created in the gridview, I just want these values to be hidden so I can access them. Thanks!

도움이 되었습니까?

해결책

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"]
    }
}

Check MSDN here.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top