User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,772 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 3861 | Replies: 1
Reply
Join Date: Dec 2007
Posts: 1
Reputation: dev1910 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dev1910 dev1910 is offline Offline
Newbie Poster

Question GidView RowDataBound Problem...

  #1  
Dec 4th, 2007
Hello frenz,
I am trying to modify the templateField itemized hyperlink on my GridView.
My problem is ,
I have 3 types of status, 'KIV','Complete'&'Incomplete'.
I must display 'KIV' in Red color font with its coresponding linkA.
As for 'Complete', it has to be in 'Green' and matched to linkB.
the 'Incomplete' status should be shown in Black color font and linked it with linkC.

To do this, i used the following method :

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim hLink As String = DataBinder.Eval(e.Row.DataItem, "STATUS").ToString()
If hLink.Equals("KIV") Then

Dim hLnk As HyperLink = CType(e.Row.FindControl("UW Status"), HyperLink)
hLnk.ForeColor = Drawing.Color.Red
hLnk.NavigateUrl = "linkA.asp?AppId=" + DataBinder.Eval(e.Row.DataItem, "APP_ID").ToString()

ElseIf hLink.Equals("Complete") Then

Dim hLnk As HyperLink = CType(e.Row.FindControl("UW Status"), HyperLink)
hLnk.ForeColor = Drawing.Color.Green
hLnk.NavigateUrl = "linkB.asp?AppId=" + DataBinder.Eval(e.Row.DataItem, "APP_ID").ToString()

Else

Dim hLnk As HyperLink = CType(e.Row.FindControl("UW Status"), HyperLink)
hLnk.ForeColor = Drawing.Color.Black
hLnk.NavigateUrl = "linkC.asp?AppId=" + DataBinder.Eval(e.Row.DataItem, "APP_ID").ToString()


End If
End If
End Sub

Problem is, im getting error when i execute the web site.The error description is 'Object reference not set to an instance of an object.'
Plz someoen help me sort it out what is the error with my coding.Realy appreciated.

thanks & regards dev
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,333
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Rep Power: 11
Solved Threads: 102
Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: GidView RowDataBound Problem...

  #2  
Dec 7th, 2007
Does that say what line of code that's happening on?

I can see that you probably just need to instantiate the HyperLink just once:

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
	If e.Row.RowType = DataControlRowType.DataRow Then
		Dim hLink As String = DataBinder.Eval(e.Row.DataItem, "STATUS").ToString()
		Dim hLnk As HyperLink = CType(e.Row.FindControl("UW Status"), HyperLink)
	
		If hLink.Equals("KIV") Then
			hLnk.ForeColor = Drawing.Color.Red
			hLnk.NavigateUrl = "linkA.asp?AppId=" + DataBinder.Eval(e.Row.DataItem, "APP_ID").ToString()

		ElseIf hLink.Equals("Complete") Then
			hLnk.ForeColor = Drawing.Color.Green
			hLnk.NavigateUrl = "linkB.asp?AppId=" + DataBinder.Eval(e.Row.DataItem, "APP_ID").ToString()

		Else
			hLnk.ForeColor = Drawing.Color.Black
			hLnk.NavigateUrl = "linkC.asp?AppId=" + DataBinder.Eval(e.Row.DataItem, "APP_ID").ToString()

		End If
	End If
End Sub

Now, if you have that, then what might be going on is that it's not finding a control in your templateField called "UW Status". Alternatively, you might need to use

e.Row.Cells[x].FindControl("UW Status")

where x is the index of the column that you know your templateField is located.
Alex Cavnar, aka alc6379
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 9:23 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC