RadGrid hyperLinkColumn + retain values to new page - asp.net

I have a radgrid populated when my page initially loads. I set a column in my radgrid as a hyperlink and was wondering how to retain the value of that particular column in the row clicked so when a new page is loaded I can use the value stored to perform an SQL query on the new page.
I am wondering if this is possible and how I would go about doing this?

Welcome to SO Jacob, I have done this before and it's not hard at all.
Example:
My select statement is "select top 5 ProductName from products"
I then created a hyperlink column and assigned the properties under the data section as seen in the screenshot below.
When run, it makes the data clickable and when clicked, it navigates to the url seen in the SS.
If you want to use it in a querystring change the DataNavigateUrlFormatString to:
http://google.com?ProductName={0}
You would then read it on your new page via:
var a = Request.QueryString["ProductName"]; //C#
dim a = Request.QuesryString("ProductName") 'Vb.net
If this is what you are after, click the green checkmark next to my answer to accept it and alert future users that this is the solution.

Related

Programmatically created RadioButtonList needs 2 clicks

I have a page (using MS Ajax). depending on other options, I may need to create a radio Button List inside a Panel.
This is done as per below.
RadioButtonList rbl = new RadioButtonList();
rbl.SelectedIndexChanged += new EventHandler(answer_Click);
rbl.AutoPostBack = true;
foreach (KeyValuePair<string, int> d in _answers)
{
ListItem li = new ListItem(d.Key.ToString(), d.Key.ToString());
li.Attributes.Add("class", "radio");
rbl.Items.Add(li);
}
p.Controls.Add(rbl);
this works fine, unless after the postback I need another RadioButton List. The list is drawn correctly, with all the correct options, but now when I click on an option the first time, it fills in and then resets. It takes a second click to get it to set and trigger the SelectedIndexChanged Event.
Im destroying and recreating the rbl once answer_Click is triggered (I know this as the next question that is created has different answers and options).
So, any ideas as to why it is I need to click twice on the second List?
Matt!
Looks like you have a ViewState issue. Controls are created after the LoadViewState trigger, so they doesn't get their values from the browser to load. You must save this value somewhere, using JS, ViewState, QueryString, Session, DB to persiste the state, and then load the selected value into each one.
Hopes this help you! Take a look here for more info about ASP.NET Page Life Cycle.

ASP.net Using a Session Varriable to move a GridView SelectedDataKey to another page

Help please!
I am pulling out what little hair I have left over this and can't find an answer.
I am attempting to move the selected row in a grid view to another page and use the SelectedDataKey or the primary key value of the selected row to indicate what data should be displayed in a grid view on another page. This is the last little bit of a school project that I can't figure out.
What I am doing on the first page is to use a button click event to set a session variable that looks something like this. Session["Select"] = GridView1.SelectedDataKey; The button will then send the user to the next page. Response.Redirect("CustomerAccounts.aspx");
Once on the next page I want to use the primary key selected on the first page to show only the data with a coresponding value on the second page by using a where statement in the next gridview. So I am setting the [CustomerID]=? Session("Session["Select"])
Am I setting up the where correctly in the second gridview?
I like setting up such things with querystrings.
I made a video tutorial on youtube doing just that a while back
http://www.youtube.com/watch?v=HRjZ_0JpO2M&list=UUgtKyNvllU9E6c2Mi8OtzCQ&index=5&feature=plcp
I also made a tutorial showing how to load the detail gridview nested in the master gridview with jquery
http://www.youtube.com/watch?v=nJp14o_1wZQ&list=UUgtKyNvllU9E6c2Mi8OtzCQ&index=4&feature=plcp

Getting textbox value from one page to another page textbox value

I am creating a form in my website and i link this form to the google docs (FORM which i created there). But this new form that i am trying to do is this in such a way that a textbox value from the first page should be passed over to the next page lets say page2 textbox value
CODE IS ROUGHLY SOMETHING LIKE THIS
PAGE 1.html,aspx,asp (Watever)
"/>
Page2.html,aspx,asp (Watever)
**readonly**"/>
So since i am using the google docs to save my data
**
form action="http://docs.google.com
i am unsure how to pass these values, tks for the help.
Presently i am just getting the values from page1 to page2 using this microsoft tutorial
http://support.microsoft.com/kb/300104
I think you need to read
How to: Pass Values Between ASP.NET Web Pages
you can store values using the approaches listed there.
Eg:
On your Page 1:
Create a textbox named textbox and an asp button.
on button.click code behind add
Session["test"] = textbox.Text;
Response.Redirect("Page2.aspx"); //Open page 2
On your Page 2 :
Creata a label named label1
Then on its Pageload Event in code behind
Add
string IpassAstringfrompage1 = Convert.ToString(Session["test"]);
label1.Text = IpassAstringfrompage1; //label1 will display TESTING from textbox on Page1
To test. On Page1 input "TESTING" on your textbox then click button
Regards

Grid View View state

I'm Using a GridView in my Application.
My GridView has a checkbox column and when the checkbox is clicked, the page is redirected to an other form.
When I return to previous from, nothing comes and GridView data is lost.
I used session and it's working fine, but I want that checkbox which was clicked to also maintain there state.
Is there better method to do this?
Upon redirection to the next page, Iterate your Gridview to update your Datatable with a checked checkbox column and then set that datatable to a session variable. I am assuming that you are already storing your source Datatable to a session.
Sorry, but no other magic work around !!!

Drop Down Box (select) set URL on postback?

I have a page with a ASP.NET DropDownBox control (HTML select) that's populated with some dynamic record values. When the user selects a record the entire contents of the page is updated to reflect the selection. If a user clicks a link and leaves the page and tries to go back, it pulls up the default unselected list, and they have to reselect it again. How would be the best way to retain their selection? I currently have the page set so if the url contains PageName.aspx?recordID=5 it will select the correct dropDown option. However I'm not sure how to change the URL's query string based on the selection.
You could throw the recordID into ViewState
ViewState["recordID"] = 5;
instead of carrying the selection in Query String.
You can check for it on page load; if it's not null then set the dropdown control appropriately.

Resources