Obtaining Data From Repeater asp.net - c#

I am an amateur as far as asp.net is concerned. What I'm trying to do is that I have a repeater control in my page that is set to show data upon selection of an item in a radio button list.
Upto this point its all good, next what I have to do is: I want a book now button for each repeater item which I can do as well.
But the question is: after user clicks book now how do I know which repeater item user has clicked? And how do I get the h_id(unique id of the table that repeater shows data of) of that item so that I can do further operations.

You could have a button or link in the repeater which an Eval("ID") as its commandargument and then use that value on postback - ala http://www.aspsnippets.com/Articles/ASPNet-Repeater-Get-Item-ItemIndex-CommandName-and-CommandArgument-on-Click-Events.aspx

Related

Store GridView to session C#.Net [duplicate]

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.

ASP GridView and DropDownList

I have an asp page with a GridView control. One of the columns in the grid view is a dropdownlist. the drop down list are filled using the RowDataBound event on the page load event. However, one of the options in the list, when selected, will popup a dialog that will allow the user to add a new item to the list, and that newly added item becomes the selected item for that drop down. This part I have working fine, but I want to be able to add the new item to the drop down list for every row in the grid. How do I, in a way, re bind the drop down list in all rows after the page has loaded without having to loop through each field?
If all the DDL's have a shared DataSource then it should just be a matter of forcing a postback after adding the new listitem. But how are you adding the new listitem?
If your popup is simply adding a new html <option> tag to an html <select> tag, this is not the same thing as updating the DDL DataSource.
For all the DDL's to show the new listitem your popup would have to perform a postback that updates the DDL datasource(s) and all the DDL controls in the GridView would need to be rebound.
This would happen automatically on a postback assuming that the DDL controls are connected to their datasource via the DataSourceID property. If you are making use of the DataSource property then you will have to call DataBind() explicitly for each DDL control, which I think you said you are doing in the GridView RowDataBound event.
Alternatively you could loop through all your ddl controls clientside and add the same item to each control, but you would lose all those changes the next time the page refreshed and I don't think that's what you want.

Javascript: history.go(-1) does not redirect me to updated previous/latest page

I have a page with a dropdownlist, gridview, a button (with c#, asp.net).
Whenever I change the selecteditem in the ddList and click on the button my gridview is populated with the data related to the selecteditem and when I click on any cell (cells contain the data with hyperklinks to a low level page).
When this high level page loads with the ddlselected value from a more hig level page it load the data related to the selected item but after I change the selecteditem in ddlist and click on the button it loads the new data and when I clik on the hyperlink in the cell data it redirects me to a new low level page and after that when i click on the back button (in the browser iexplorer), i am redirected to the previous page but it always loses that ddlist latest selected item and displays the old ddlist select item's data.
I am generating the breadcrumbs using hyperlinks with Javascript: history.go(-1).
I believe the cache on the client is not updated when I change the ddlist selected item. but during the debugging when I check in the immediate window I see that it always updates the ddlist selecteditem.
Any help would be appreciated a lot.
thank you.

Transferring DropDownList values from one page to the next

I have 2 pages, both with 3 similar DropDownLists. The first DropDownList needs to be populated before selecting the second, and the second before the third (which then populates a gridview).
Usually, a user will view data on one page, click a button, and then view data on the next page (usually with the same DropDownList selections). Is there any way to have the dropdownlists pre-populated with their old selections?
You can pass values from one page to the other using the PreviousPage parameter that asp.net provides you. A small example:
You set the second page on the submit button as:
PostBackUrl="SecondPage.aspx"
On SecondPage.aspx you declare where you can get informations
<%# PreviousPageType VirtualPath="~/FirstPage.aspx" %>
and you get them by...
if (Page.PreviousPage != null)
{
if(Page.PreviousPage.IsCrossPagePostBack == true)
{
// and get the controls of the previous page as
var SomeVariable = PreviousPage.DropDownlListId.SelectedValue;
}
}
Some reference.
Cross-Page Posting in ASP.NET Web Pages
ASP.NET how to access public properties?
Cross-page postbacks and back again retaining data from source page
Cross-page posting. Is it a good pratice to use PreviousPage in Asp.net?
If you have the form where the button that the users click post to the second page, the second page can look for the values of the DDL and set them on page load.
There is a way:
pass selections to the second page either via Session or Query String
populate first dropdown
select appropriate item
repeat 2-3 for the rest of dropdowns
If you're looking for a magic solution that just "does that", I don't think this is possible.
p.s. You might rethink your design (if this is an option) and have the grid on the first page; bind the grid when user selects a value from the last dropdown (make sure you have AutoPostback set to True on your last dropdown in order to trigger the final postback)

Display selected row of Gridview data to next page in another Gridview?

How can I Display selected row of Gridview data to next page in another Gridview?
For example,
In listing page I want to select particular row and take that data to another page and display over there.
I have two grid view one in 1st page
and next one in 2nd page. Now when I
select a record in 1st page gridview,
than that record will display on 2nd
page gridview on submit button click
from 1st page.
Pass the key of the record via the querystring... and then in rowdatabound event, select the row when the data bound record matches the key in the QS.
For more protection, you can use session to store the variable.
Why not have 2 gridviews, one above the other? The top gridview could be made to only show 1 record which is set to the id of the 2nd gridviews selected item identifier in code. Then in 2nd gridview, have an empty selected item template so that the selected item only shows once for both gridviews. That way the 2nd gridview is free to page through the entire set whilst the first retains the selected item for display above?

Categories