On the other page I have GridView that I want to print an image based on the query string. For example if the Department_ID= 2, I want o pull back the Map_Location with a Map_ID=2 from my table. Not sure how to set that up. Currently it is returning all
the images in the table. Thanks
SqlDataSource1.SelectCommand = "SELECT yourImagefield From yourtable WHERE Department_ID = '" + deptID + "'";
(Path of the images are stored in yourImageField)
YourGridView,DataSource = SqlDataSource1;
YourGridView.DataBind();
In Gridview Put an Image control in a templatefield and bind its NavigateUrl Property to "yourImageField".
I did this. I am not getting any errors jsut when i navigate to the page the image is not displaying. I am just getting the little white box with the red x.
Little white box with the red x means that src path of Image is incorrect. Inspect Image element in browser, and look what path is set for src attribute. Maybe you're storing wrong path in Db.
Will you please tell us in which folder the images are stored and what are the value stored in table field? If only the file names are stored in DB and the images are saved in a sub folder "Maps" in your site, the HTMl markup of your Image control should
be like this.
gordon1221
Member
12 Points
117 Posts
Image displayiing based on QueryString
Apr 27, 2012 04:47 PM|LINK
I am passing a query string from a hyperlink navigate url to another page:
<asp:HyperLink ID="Department_ID" runat="server"ImageUrl='<%# String.Format("~/Images/button.png",Eval("Department_ID")) %>'
NavigateUrl='<%# "~/Department_Maps.aspx?Department_ID="+Eval("Department_ID") %>' Target="_parent">
On the other page I have GridView that I want to print an image based on the query string. For example if the Department_ID= 2, I want o pull back the Map_Location with a Map_ID=2 from my table. Not sure how to set that up. Currently it is returning all the images in the table. Thanks
<asp:ImageField DataImageUrlField="Map_Location">
</asp:ImageField>
RichardY
Star
8376 Points
1573 Posts
Re: Image displayiing based on QueryString
Apr 27, 2012 04:52 PM|LINK
Might help if you posted the code that shows how items are being selected for the gridview. What is the DataSource for the gridview?
basheerkal
Star
10672 Points
2426 Posts
Re: Image displayiing based on QueryString
Apr 27, 2012 05:09 PM|LINK
if you use a gridview for diplaying image..
Put a SqlDataSource1 in Department_maps.aspx page connecting to your database.
In the pageLoad event of this page get the Value of DepartmentID as
string deptID = Request.QueryStriung("Department_ID");
SqlDataSource1.SelectCommand = "SELECT yourImagefield From yourtable WHERE Department_ID = '" + deptID + "'";
(Path of the images are stored in yourImageField)
YourGridView,DataSource = SqlDataSource1;
YourGridView.DataBind();
In Gridview Put an Image control in a templatefield and bind its NavigateUrl Property to "yourImageField".
(Talk less..Work more)
gordon1221
Member
12 Points
117 Posts
Re: Image displayiing based on QueryString
Apr 27, 2012 05:22 PM|LINK
That would help if I supplied more information:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Map_ID" DataSourceID="SqlDataSource1"
EnableModelValidation
="True">
<Columns
>
<asp:ImageField DataImageUrlField
="Map_Location">
</asp:ImageField
>
<asp:HyperLinkField DataNavigateUrlFields="Map_ID"
/>
</Columns
>
</asp:GridView
>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Way_FinderConnectionString1 %>"
SelectCommand
="SELECT Map_ID, Map_Location FROM Map_Table INNER JOIN Department_Table ON Department_Table.Department_ID = Map_Table.Map_ID">
</asp:SqlDataSource>
basheerkal
Star
10672 Points
2426 Posts
Re: Image displayiing based on QueryString
Apr 27, 2012 06:07 PM|LINK
That is in First page.
Try what I suggested in Second page. Get the request.Query String value and create the query as you need ..
(Talk less..Work more)
RichardY
Star
8376 Points
1573 Posts
Re: Image displayiing based on QueryString
Apr 27, 2012 06:11 PM|LINK
Looks like basheerkal provided the right answer.
_Manvel_
Contributor
4240 Points
922 Posts
Re: Image displayiing based on QueryString
Apr 27, 2012 06:31 PM|LINK
You need to modify SelectCommand to include Where condition
Also specify SelectParameters for your SqlDataSource control
<SelectParameters> <asp:QueryStringParameter Name="DepartmentId" QueryStringField="Department_ID" Type="Int32" /> </SelectParameters>That's it. You can check up this link, for more complete example
http://forums.asp.net/t/1516675.aspx
gordon1221
Member
12 Points
117 Posts
Re: Image displayiing based on QueryString
Apr 27, 2012 06:45 PM|LINK
I did this. I am not getting any errors jsut when i navigate to the page the image is not displaying. I am just getting the little white box with the red x.
_Manvel_
Contributor
4240 Points
922 Posts
Re: Image displayiing based on QueryString
Apr 27, 2012 08:57 PM|LINK
Little white box with the red x means that src path of Image is incorrect. Inspect Image element in browser, and look what path is set for src attribute. Maybe you're storing wrong path in Db.
basheerkal
Star
10672 Points
2426 Posts
Re: Image displayiing based on QueryString
Apr 28, 2012 01:27 AM|LINK
Will you please tell us in which folder the images are stored and what are the value stored in table field? If only the file names are stored in DB and the images are saved in a sub folder "Maps" in your site, the HTMl markup of your Image control should be like this.
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "~/Maps/" + Eval("yourImageField")%>' />(Talk less..Work more)