p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 4 General Discussion (http://p2p.wrox.com/forumdisplay.php?f=561)
-   -   Set ImageButton.ImageUrl (http://p2p.wrox.com/showthread.php?t=84873)

aspless August 26th, 2011 06:54 PM

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

aspless August 26th, 2011 07:42 PM

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?

aspless August 26th, 2011 08:52 PM

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.

aspless August 26th, 2011 09:55 PM

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



All times are GMT -4. The time now is 09:57 PM.

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