How to display an image field in each row of DataGrid

If the image field is a string representing a image file name, then: … <asp:TemplateColumn> <ItemTemplate> <img src=’<%#DataBinder.Eval (Container.DataItem, ‘Photo’)%>’> </ItemTemplate> </asp:TemplateColumn> …

How do I conditionally set the text color of a cell in my Datagrid based on the cell’s/fields’s value?

In the ItemDataBound event you can access the Cells() collection of the current Datagrid item (or row) and set it’s ForeColor. <asp:DataGrid OnItemDataBound=’ItemDB’ id=’DataGrid1′ runat=’server’></asp:DataGrid> VB.NET protected Sub ItemDB(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) If (e.Item.ItemType = ListItemType.Item Or _ e.Item.ItemType = ListItemType.AlternatingItem) Then If e.Item.DataItem(6) > 15 Then e.Item.Cells(6).ForeColor = System.Drawing.Color.Green Else e.Item.Cells(6).ForeColor = System.Drawing.Color.Red End If End If End Sub C# protected void ItemDB(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if((e.Item.ItemType ==ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem) ) { if (Convert.ToInt16 (e.Item.Cells[6].Text) >15 ) { e.Item.Cells[6].ForeColor = System.Drawing.Color.Green; } else { e.Item.Cells[6].ForeColor = System.Drawing.Color.Red; } } } In Cells[x]/Cells(x) x=> index number to the list of fields in the row.

How to open a new window with multiple parameters when clicked on a hyperlink in a column in a datagrid

The column should be defined as a TemplateColumn as follows and the NavigateUrl for that hyperlink can be set as follows to open a new window with parameters varying based on the row in which the hyperlink is present. <asp:TemplateColumn > <ItemTemplate> <asp:Hyperlink ID=’Hyperlink2′ Runat=’Server’ NavigateUrl= <%#’javascript:my_window=window.open(’webform2.aspx?id=’ + DataBinder.Eval(Container.DataItem,’productid’).ToString() + ‘&Supplierid=’ + DataBinder.Eval(Container.DataItem,’SupplierID’).ToString() + ‘’,’my_window’,’width=300,height=300’);my_window.focus()’ %> text=<%#DataBinder.Eval(Container.DataItem,’ProductName’).ToString() %>> </asp:Hyperlink> </ItemTemplate> </asp:TemplateColumn> The above approach would avoid the problem of showing the screen of [Object] on the parent page