Button uses a command which when using the debug runs with no problems, however the label does not change. The Listview and gridviews contained within (data not posted here) work with no problems.
Hopefully someone can help and let me know where I am going wrong. My overall aim is to put the label into a session variable so I can execute a query with it as a variable.
Then we could retrieve the value and save it in session variable in ItemCommandevent.
if (e.CommandName == "Select")
{
string id = e.CommandArgument.ToString();
Session["id"] = id;
}
Best Regards,
Fei Han
variablelistviewlabel
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
I have created a button in each line of the listview which I need to use to access another page, but it's the employeeid in column 1 that I use to bring up the correct data.
Using the 2nd suggestion (below yours) I can get the employeeid as text on the button, but can not manage to get it into a session variable, which is what I want.
Thank you Oned_gk for your suggestion, but don't want to change the label text, it's already set as per my employeeID. I need the label to be a session variable. I can normally get it working, it's just it changes on every row.
None
0 Points
6 Posts
Listview label into a session variable
Nov 18, 2015 10:43 AM|chrismusic79|LINK
Hi,
After having my previous problem solved here I thought I would again turn to this site for help.
It seems such a simple event, but I can't get it to work correctly. To aid with security I've changed all the names, but the idea is still the same.
I have a aspx wep page that has a label (idlabel). As per my code it currently reads "Nothing".
On Page_Load I can change that label to read "Loaded".
The problem is when I try and change the label again after using a button located within my listview.
Button uses a command which when using the debug runs with no problems, however the label does not change. The Listview and gridviews contained within (data not posted here) work with no problems.
Hopefully someone can help and let me know where I am going wrong. My overall aim is to put the label into a session variable so I can execute a query with it as a variable.
Thanks in advanced
variable listview label
All-Star
29523 Points
6026 Posts
Re: Listview label into a session variable
Nov 18, 2015 11:27 AM|budugu|LINK
Code redirects to same page(?)...so page_load will execute again
protected void Page_Load(object sender, EventArgs e)
{ idlabel.Text = "Loaded"; }
variable listview label
"Don't be afraid to be wrong; otherwise you'll never be right."
None
0 Points
6 Posts
Re: Listview label into a session variable
Nov 18, 2015 11:55 AM|chrismusic79|LINK
Hi,
Such a silly mistake. I can't believe I did that. Sorry. I knew I was doing something wrong, but never thought of that. Thank you.
Any idea how to get the ID into a session variable, depending which record is selected?
variable listview label
All-Star
29523 Points
6026 Posts
Re: Listview label into a session variable
Nov 18, 2015 12:42 PM|budugu|LINK
Something like this...
variable listview label
"Don't be afraid to be wrong; otherwise you'll never be right."
None
0 Points
6 Posts
Re: Listview label into a session variable
Nov 18, 2015 01:10 PM|chrismusic79|LINK
Hi,
I get "-1" but I need the ID that my listview shows in the first column, which changes every record.
variable listview label
All-Star
29523 Points
6026 Posts
Re: Listview label into a session variable
Nov 18, 2015 09:06 PM|budugu|LINK
ListView selected items are a collection, can get values like this..
variable listview label
"Don't be afraid to be wrong; otherwise you'll never be right."
All-Star
40565 Points
6233 Posts
Microsoft
Re: Listview label into a session variable
Nov 19, 2015 04:38 AM|Fei Han - MSFT|LINK
Hi chrismusic79,
You could save ID field in CommandArgument
Then we could retrieve the value and save it in session variable in ItemCommand event.
Best Regards,
Fei Han
variable listview label
Member
1 Points
10 Posts
Re: Listview label into a session variable
Nov 24, 2015 11:41 AM|chrismusic1979|LINK
Hi,
Sorry, can't get into the old account. Had to create a new one.
Using your suggestion I can't seem to get it working. I wonder if we are not on the same wavelength.
My Listview is as per an older thred of mine (http://forums.asp.net/p/2076610/5989505.aspx?Re+Showing+a+gridview+within+a+listview)
I have created a button in each line of the listview which I need to use to access another page, but it's the employeeid in column 1 that I use to bring up the correct data.
Using the 2nd suggestion (below yours) I can get the employeeid as text on the button, but can not manage to get it into a session variable, which is what I want.
Thank you for your time so far.
All-Star
52813 Points
15769 Posts
Re: Listview label into a session variable
Nov 25, 2015 07:37 AM|oned_gk|LINK
If you want to change the label text property, you should not change the label text in page_load event in every postback
Suwandi - Non Graduate Programmer
Member
1 Points
10 Posts
Re: Listview label into a session variable
Nov 26, 2015 10:23 AM|chrismusic1979|LINK
Hi,
Thank you Oned_gk for your suggestion, but don't want to change the label text, it's already set as per my employeeID. I need the label to be a session variable. I can normally get it working, it's just it changes on every row.