have a GridView with two columns: Part Number | Part Details
When I search for the part number 12345, the gridview will display like this
PartNumber | PartDetails
12345 | image1 (image1 will see as document picture)
If I search Part Number and doesn't get any data results in gridview the information will be:
PartNumber | PartDetails
0 | image2 (image2 will see as red cross picture)
How to change the image2 in the same column cell 1 in the GridView when the data results are "0" ?
Here is my code:
<asp:GridView
Width="570px"
runat ="server"
ID="grdView1"
PageSize ="15"
OnRowDataBound ="grdView1_OnRowDataBound"
RowStyle-Font-Size ="13pt"
RowStyle-Font-Names ="Tahoma"
RowStyle-Height ="30px"
AlternatingRowStyle-BackColor="#cccccc"
CellPadding="5"
AllowResizeColumn ="False"
AutoGenerateColumns = "False"
HeaderStyle-CssClass ="HeaderStyle"
BackColor="White"
BorderColor="#CCCCCC"
BorderStyle="Solid"
BorderWidth="1px"
ForeColor="Black"
GridLines="Both">
<columns>
<asp:HyperLink
ID="HplPartNumber"
runat="server"
NavigateUrl ='<%# String.Format("~/ABC/AMT.aspx?PartNumber{0}>'
Text='<%# DataBinder.Eval(Container.DataItem, "partnumber").ToString%>' >
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField
DataNavigateUrlFields ="PartNumber"
DataNavigateUrlFormatString ="ABC/AMT.aspx?PartNumber{0}"
DataTextField ="PartNumber"
SortExpression ="PartNumber"
HeaderText ="Part Details"
DataTextFormatString ="<img style='margin-top: 2px;' src='../Images/DocImage1.png' alt=info' width='25' height='25' title='Part Number'Target ="_blank">
<asp:HyperLinkField
DataNavigateUrlFields ="PartNumber"
DataNavigateUrlFormatString ="ABC/AMT.aspx?PartNumber{0}"
DataTextField ="PartNumber"
SortExpression ="PartNumber"
HeaderText ="Part Details"
DataTextFormatString ="<img style='margin-top: 2px;' src='../Images/DocImage2.png' alt=info' width='25' height='25' title='Part Details'>
</columns>
</asp:GridView>
Protected Sub grdView1_OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
Try
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ParDetImage1Link As HyperLink = DirectCast(e.Row.Cells(1).Controls(0), HyperLink)
Dim ParDetImage2Link As HyperLink = DirectCast(e.Row.Cells(1).Controls(0), HyperLink)
Dim Link As HyperLink = TryCast(e.Row.FindControl("HplPartNumber"), HyperLink)
If Link.Text = 0 Then
Link.Text = "0"
ParDetImage2Link.Enabled = False
else
ParDetImage1Link.Enabled = True
end if
end if
end sub
Your help is much appreciated. Thanks.