if (dc.GetTable<MyBusinessObjects.Person>().Contains(personToFind)
//variables used:
//dc = MyDataContext
//personToFind = instance of the data class
tags: DataContext, Find, Contains, Search, item, c#, .net, DataContext.Contains, DataContext.Find,
if (dc.GetTable<MyBusinessObjects.Person>().Contains(personToFind)
<asp:DataGrid runat="server" ID="MyGrid"
CellSpacing="0"
CellPadding="6"
Width="100%"
AllowSorting="True"
OnSortCommand="MyGrid_Sorting"
OnItemDataBound="MyGrid_ItemDataBound"
OnItemCommand="MyGrid_ItemCommand"
Visible="true"
PagerStyle-Mode="NumericPages"
AutoGenerateColumns="False"
AllowPaging="True"
AllowCustomPaging="True" AllowCustomPaging="True"
OnPageIndexChanged="MyGrid_PageIndexChanging"
protected void myDataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
//Check if this is the header row of the grid:
if (e.Item.ItemType == ListItemType.Header)
//Loop through the columns (cells) of the header row
foreach(TableCell cell in e.Item.Cells)
{
string datagridLinkButtontext = string.Empty;
LinkButton lb = new LinkButton();
try
{
lb = (LinkButton)cell.Controls[0];
}
catch (InvalidCastException ex)
{
// do nothing if its not a linkbutton
}
if (lb != null) datagridLinkButtontext = lb.Text;
// now you can use the above text to determine which column you're working with,
// and do something with it, i.e as in my case set the tooltip:
cell.ToolTip = getTooltipForColumn(datagridLinkButtontext);
}
...
}