Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 26th, 2011, 06:54 PM
Friend of Wrox
 
Join Date: Dec 2006
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
 
Old August 26th, 2011, 07:42 PM
Friend of Wrox
 
Join Date: Dec 2006
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?
 
Old August 26th, 2011, 08:52 PM
Friend of Wrox
 
Join Date: Dec 2006
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.
 
Old August 26th, 2011, 09:55 PM
Friend of Wrox
 
Join Date: Dec 2006
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





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





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