Displaying image on a different page - c#

Hallo there
I have and imageField as part of a gridview and would like to know how I can view this image in a different page when I select the row with a button(field).
When I add the information to a database the imageUrl is added to the database and this I tie up with the name of an uploaded image and subsequently the image is displayed in the gridview.
Is it possible for me to display this image on a different web page as well
thanks

Instead of storing image in session, why not populate Session["ImageID"] value on Button click?
Set gridview's OnRowCommand property to a method that will set Session["ImageID"] to the current row's DataKey, then do a redirect to that other page that will get value from Session["ImageID"] and get image URL for that ID from database. Don't forget to also perform Session.Remove("ImageID"). That way you'll keep your session object as small as possible.

Yes ,you can , i think if you store the selected image information in a Session.May be, there are other ways , but the first thing comes in my mind in this case using the session.

Related

Form View page redirect

I am using a FormView to display data with a SqlDataSource and my platform is MSVS2013.
Lets say I have 4 data in Data table so it displays fist data set with page numbers at the bottom.
But if I select 2nd or 3rd on any other page number then it will refresh the page and set proper data in the FormView. The problem is if I select any other page number it will change data and not navigate view back to same position to the page, instead it shows the top position of the page.
Can any one help Thanks in advance!
Use update panel... it will give the solution

Retrieve and save gridview in session

I have a page for searching when I write my name for example in textbox it will search and display the results in a GridView. I'm using an EntityDataSource with a QueryExtender so I didn't write any code in C#.
The problem is: in the GridView I have a hyperlink when I click it, it will go to another page, ok fine then when I return to the previous page the GridView does not show the results of the search when I was left because of the postback (update panel) it show the whole data from EntityDataSource.
I think I have to use session but I don't know how I can do it, I mean how I can save the GridView in session and how I can retrieve it in page_load.

gridview click event that uses object data

I have a class (let's call it Object) that contains an ID and some other data. I want to display the IDs in a gridview. When the user clicks on an ID in the gridview table, I want the ability to add code that accesses the object of the ID and display the Object's details (it's ID and other stored data).
So far I've been able to store the data in a tabletable and set it as the gridview source, but I haven't been able to extend the click event feature.
Any ideas on how to implement this in C#?
The object used to load into the GridView is gone as soon as the page unloads. The contents are retained in viewstate, but the object is not there. What you need to do is query the data again using the selected ID. Or link the Grid to a DetailsView, which will query the data, as #Wahtever suggested in the comments.

How to edit a row in asp.net?

I have records that are displayed on a page and I have a small "edit" icon on the very right of each row.
So when I click the icon I want the user to edit "selected" row.
Now, I am generating the records and images behind code! so i am not using a control it generated a html code then i do something like this
output.InnerHTML = generatedCode;
Question, how can i create a function to determine which icon has been clicked and also that id of that icon?
If you are doing this with tables you must generate some unique id for each row edit link so that you can identify which row you have to edit. Apart from this there are pretty much easy way to display records in asp.net i.e GridView

change image on postback

So, here's the scenario:
I have a page in my asp.net c# based website, which displays data dynamically after taking the request from query strings.
For example:
Brand=HTC&model=Wildfire
Now, in this page I want to display all the deals available in each network separately.
So, on the first pageload, I retrieve the data from the tables of each network that has the requested handset in a deal, store it as a datatable in the cache.
I have a datalist for displaying the imagebuttons of the networks that have the deals of that handset. The user will click on the imagebutton of a network to view the deals of that network.
To display the deals, I am using a gridview which retrieves its datasource from the cache. Also, I have provided filtering of the rows through dropdowns in each columns' header of the gridview.
All this is inside an updatepanel.
Everything's working fine.
The Problem:
I want that whenever the user clicks a network's image button, an image should appear above the gridview, containing the logo of that network.
Things that I have tried:
I am storing the networkname in the cache(which also required for filtering the gridview), whenever an imagebutton is clicked. Then, on pageload, I'm doing this:
if(ScriptManager1.IsInAsyncPostBack)
{
Image img = new Image();
img.ImageUrl = "images/" + Cache["network"] + "_logo.jpg";
nw_image.Controls.Clear();
nw_image.Controls.Add(img);
}
where, nw_image is a tablecell which i'm using to display the selected network logo.
and also I've saved the network logos in the images folder as: 'network'_logo.jpg
eg: 3_logo.jpg, orange_logo.jpg
The result of this is that when I click a new image button, the image that is displayed is that of the previous network, i.e. the cache is always one postback late.
Please Help!
Thanks!
Rather than using dynamic controls (i.e. creating the Image control manually on a postback), it would be much easier to just define an Image control in your page markup and default its Visible property to false. Then on your postback, set the ImageUrl property to the correct URL, and the Visible property to true.
Also, ensure that your nw_image table cell is inside your UpdatePanel, and you either have ChildrenAsTriggers set to true on the update panel (this is the default), or have specified an AsyncPostbackTrigger for the Click event of the ImageButton.
At last I've got it to work.
I've now put a static image without any properties except id = "net_img" , runat = "server" and EnableViewState = "true".
And instead of taking the network name from the cache, I'm changing the image in the click event of the ImageButton according to the Imagebutton that is clicked.
And it works now! :)

Categories

Resources