Hello,
I have access database which have hyperlink column, and values as "/yes.bmp", "/no.bmp".
Then in asp.net have a GridView with ImageField which in browser will show Yes image, or No image. ImageField Properties >> DataImageUrlFormatString: ~/images/{0}.jpg.
My goal is to get in vb.net code a value from GridView's imagefield.
For example, if GridViews.rows(x).cells(x).ImageField(0).value is "Yes.bmp" then ....
This example I have wrote just as expression, for better understanding.
I know how to get GridViews text values, or data values, but for Images I have never done it.
Thank you.
4 Replies - 6390 Views - Last Post: 08 May 2011 - 07:07 AM
Replies To: How to get GridView's imagefield value in vb.net?
#2
Re: How to get GridView's imagefield value in vb.net?
Posted 06 May 2011 - 04:50 AM
What have you tried so far?
#3
Re: How to get GridView's imagefield value in vb.net?
Posted 06 May 2011 - 12:13 PM
I have a calendar table from database which show two images for Yes, or No.
My goal is something like that:
I can do parallel table with text, or number values and used above code. But, why to do another table, if I already have one.
Here is a asp.net code.
Anyway, I'm still learning asp.net, vb.net. I do not know at the moment how to do it.
My goal is something like that:
If Gridview1.rows(0).cells(1).text = "no.bmp" then DropDownListFrom.Items(1).Enabled = False else If Gridview1.rows(0).cells(1).text = "yes.bmp" then DropDownListFrom.Items(1).Enabled = True End If
I can do parallel table with text, or number values and used above code. But, why to do another table, if I already have one.
Here is a asp.net code.
<asp:GridView ID="JanGridView2" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="JanSqlDataSource1" BorderColor="#7597DD"
BorderWidth="1px" EmptyDataText="Ni podatkov s strani naročnika."
ShowHeaderWhenEmpty="True">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" Visible="False" />
<asp:HyperLinkField DataNavigateUrlFields="id"
DataNavigateUrlFormatString="januar.aspx?id={0}" DataTextField="id"
DataTextFormatString="Podrobno" HeaderText="1.JANUAR" >
<ControlStyle Font-Bold="True" ForeColor="#003399" />
<HeaderStyle Width="80px" ForeColor="#004080" />
<ItemStyle Font-Underline="True" Font-Bold="True" ForeColor="#003399" />
</asp:HyperLinkField>
<asp:ImageField DataImageUrlField="jan1"
DataImageUrlFormatString="~/photos/{0}.bmp" HeaderText="1">
<HeaderStyle HorizontalAlign="Center" Width="25px" BorderColor="#7597DD"
BorderWidth="1px" />
<ItemStyle BorderColor="#7597DD" BorderWidth="1px" />
</asp:ImageField>
<asp:ImageField DataImageUrlField="jan2"
DataImageUrlFormatString="~/photos/{0}.bmp" HeaderText="2">
<HeaderStyle HorizontalAlign="Center" Width="25px" BorderColor="#7597DD"
BorderWidth="1px" />
<ItemStyle BorderColor="#7597DD" BorderWidth="1px" />
</asp:ImageField>
Anyway, I'm still learning asp.net, vb.net. I do not know at the moment how to do it.
#4
Re: How to get GridView's imagefield value in vb.net?
Posted 06 May 2011 - 02:26 PM
You might try converting the databound control into a template field. They are usually a little easier to work with in situations like this, in my opinion. To convert a databound column into a template field you select the little arrow that pops up on the gridview when in design mode and select edit columns. You'll see a list of the column controls on the bottom left, select the one that has the imagefield. beneath the options panel on the right there is a link button that says something like "convert to templated control" or something similar. After you close that wizard you can switch from design view back to code view and that column should look something like
in the codebehind you should then be able to do something like
to get the image control out of the GridView. You should then be able to get what you need from the images properties. I think the above is right but I normally use C# so the syntax could be off on the VB.Net stuff
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Bind("ImageColumn") %>' />
</ItemTemplate>
</asp:TemplateField>
in the codebehind you should then be able to do something like
Dim img As Image = CType(GridView1.Rows(0).FindControl("Image1"), Image)
to get the image control out of the GridView. You should then be able to get what you need from the images properties. I think the above is right but I normally use C# so the syntax could be off on the VB.Net stuff
This post has been edited by Nakor: 06 May 2011 - 02:30 PM
#5
Re: How to get GridView's imagefield value in vb.net?
Posted 08 May 2011 - 07:07 AM
Nakor, thank you for help. I've got a results.
I have a little changed code in aspx structure.
Vb.net code:
Result of Textbox1 is "~/yes.bmp##.bmp"
This examples can help also to another users.
I have a little changed code in aspx structure.
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("jan1", "~{0}.bmp") %>' />
</ItemTemplate>
</asp:TemplateField>
Vb.net code:
Dim img As Image = CType(GridView1.Rows(0).FindControl("image1"), Image)
TextBox1.Text = img.ImageUrl
Result of Textbox1 is "~/yes.bmp##.bmp"
This examples can help also to another users.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|