Using DataGrid ItemDataBound Event to Check Value
I've got a DataGrid where the datasource is bound with a SqlDataReader
object:
SqlDataReader areader = runner.Reader;
dgSearchResults.DataSource = areader;
dgSearchResults.DataBind();
I've created an ItemDataBound event for my grid and I want to check the
Value of a specific Column/Cell that while each item is bound so I can
enable/disable some flags.
How can I get the value of a specific cell "SvcID" on the ItemDataBound?
Here is my code:
public void dgSearchResults_ItemDataBound(object sender,
DataGridItemEventArgs e)
{
if (ViewState["SvcIDs"] != null)
{
if (e.Item != null)
{
var svcIds = (List<int>) ViewState["SvcIDs"];
if (svcIds.Contains(Convert.ToInt32(**DataGrid SvcID Goes
Here**))
{
//TODO: enable/disable some icons
}
}
}
}
I've used RowDataBound events before but not for a DataGrid control, and
the required steps are a bit different it seems.
What is the code to check the value of Column "SvcID" in my DataGrid
against my SvcIds (using an Index) List?
Thanks
No comments:
Post a Comment