Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 26th, 2011, 06:54 PM
Friend of Wrox
Points: 489, Level: 7
Points: 489, Level: 7 Points: 489, Level: 7 Points: 489, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2006
Location: Berkshire, United Kingdom.
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default Set ImageButton.ImageUrl

Chaps..

I am hoping i'm not to far off on this one..

I am reading a value from a datasource and based on a simple bit value wish to alter the ImageButton.ImageUrl associated with a gridview.

The Gridview Variables are:

Code:
 
<asp:GridView ID="GridView1" DataSourceID="SqlDataSource1" ect ect>
<asp:TemplateFieldHeaderText="Sub Groups">
<ItemTemplate>
<asp:ImageButtonID="ImgButGridGroup"runat="server"CausesValidation="false"CommandName="showSubGroups"ImageUrl="~/images/icons/gridgroups.jpg"Text="Button"/>
</ItemTemplate>
</asp:TemplateField>
My VB Code is

Code:
ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load
Dim dvSql AsDataView = DirectCast(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
ForEach drvSql AsDataRowViewIn dvSql
Dim SubGrpImgVal AsInteger = drvSql("subgroupimg").ToString
Dim ImgButGridGroup AsImageButton = CType(GridView1.FindControl("ImgButGridGroup"), ImageButton)
If SubGrpImgVal = 1 Then
ImgButGridGroup.ImageUrl = "~/images/icons/gridmembers.jpg"
Else
ImgButGridGroup.ImageUrl = "~/images/background/1pxWhiteSpace.jpg"
EndIf
NextEndSub
As far as i can tell from the debug watch the datasource value is comming through fine..

The error i am getting is
Code:
Object reference not set to an instance of an object
Which indicates that there is a mismatch but can't see what part of the ImageButton reference is not working.

Still very much getting to grips with VB..

Any assist would be appreciated!!

Cheers

Aspless
Reply With Quote
  #2 (permalink)  
Old August 26th, 2011, 07:42 PM
Friend of Wrox
Points: 489, Level: 7
Points: 489, Level: 7 Points: 489, Level: 7 Points: 489, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2006
Location: Berkshire, United Kingdom.
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default

Ok .. Now seeing that i am not getting any value from
dvSql

Latest effort is

Code:
Dim dvSql AsDataView = DirectCast(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
Dim index AsInteger = GridView1.SelectedIndex
ForEach drvSql AsDataRowViewIn dvSql
index = 0
Dim SubGrpImgVal AsInteger = drvSql("subgroupimg").ToString
If SubGrpImgVal = 1 Then
Dim ImgButGridGroup AsImageButton = CType(GridView1.Rows(index).FindControl("ImgButGridGroup"), ImageButton)
ImgButGridGroup.ImageUrl = "~/images/icons/gridmembers.jpg"
Else
Dim ImgButGridGroup AsImageButton = CType(GridView1.Rows(index).FindControl("ImgButGridGroup"), ImageButton)
ImgButGridGroup.ImageUrl = "~/images/background/1pxWhiteSpace.jpg"
EndIf
index = index + 1
Next
Which essentially removes the image from row 1 and as there is no data being returned i'm not supprised ..

First time i have tried to extract from the Datasource so that does not help!

Thoughts?
Reply With Quote
  #3 (permalink)  
Old August 26th, 2011, 08:52 PM
Friend of Wrox
Points: 489, Level: 7
Points: 489, Level: 7 Points: 489, Level: 7 Points: 489, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2006
Location: Berkshire, United Kingdom.
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default

Ok ..

After further testing i am getting data out of the sqldatasource1 running the following script:

Code:
Dim dvAccess AsDataView = DirectCast(SqlDataSource1.[Select](DataSourceSelectArguments.Empty), DataView)
Label1.Text = dvAccess(0)(4).ToString() & "<br>"
Label2.Text = dvAccess(1)(4).ToString() & "<br>"
Label3.Text = dvAccess(2)(4).ToString() & "<br>"
Label4.Text = dvAccess(3)(4).ToString() & "<br>"
Could someone do me the small favour of helping me get this into a proper Loop through the data.
Reply With Quote
  #4 (permalink)  
Old August 26th, 2011, 09:55 PM
Friend of Wrox
Points: 489, Level: 7
Points: 489, Level: 7 Points: 489, Level: 7 Points: 489, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2006
Location: Berkshire, United Kingdom.
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default

Making progress and just need to get the index working properly

Any nudge?

Code:
Dim dvAccess AsDataView = DirectCast(SqlDataSource1.[Select](DataSourceSelectArguments.Empty), DataView)
Dim index AsInteger'= GridView1.SelectedIndex
index = 0
ForEach rowView AsDataRowViewIn dvAccess
'Create(index)
If index = 0 Then
index = 1
Else
index = index + 1
EndIf
Dim row AsDataRow = rowView.Row ' Do something '
Label1.Text = row(4)
If row(4) = 1 Then
Dim ImgButGridGroup AsImageButton = CType(GridView1.Rows(index).FindControl("ImgButGridGroup"), ImageButton)
ImgButGridGroup.ImageUrl = "~/images/icons/gridmembers.jpg"
Else
Dim ImgButGridGroup AsImageButton = CType(GridView1.Rows(index).FindControl("ImgButGridGroup"), ImageButton)
ImgButGridGroup.ImageUrl = "~/images/background/1pxWhiteSpace.jpg"
EndIf
 
Next
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Eval ImageUrl doesn´t work studioc BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 May 23rd, 2008 05:57 AM
ImageUrl syntax almotions ASP.NET 2.0 Basics 2 January 24th, 2008 03:47 AM
Databinding the ImageURL Prop of an Image Control Aaron Edwards ASP.NET 2.0 Professional 1 November 22nd, 2007 12:53 PM
Refresh imagebutton ianH ASP.NET 2.0 Basics 1 September 13th, 2006 04:40 PM



All times are GMT -4. The time now is 10:19 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.