View Single Post
  #1 (permalink)  
Old August 26th, 2011, 06:54 PM
aspless aspless is offline
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