| |

VerySource

 Forgot password?
 Register
Search
View: 1588|Reply: 19

The problem of passing the value of a column in the DataGrid through Session when clicking

[Copy link]

3

Threads

26

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-10-17 12:00:02
| Show all posts |Read mode
I use the following method to open a new page when the user clicks on the DataGrid:
private void DataGrid1_ItemDataBound_1(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
e.Item.Attributes.Add ("onclick","window.open('yl.aspx?ID="+e.Item.Cells [0].Text +"')");
}
Now I don’t want to pass the value through url, I want to do it through Session:
private void DataGrid1_ItemDataBound_1(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
e.Item.Attributes.Add ("onclick","window.open('yl.aspx?')");
Session["LoginName"]=e.Item.Cells [0].Text;
}
But when I received it on another page, I found that Session["LoginName"] is a space character&nbsp, what is going on?
Reply

Use magic Report

0

Threads

32

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2020-10-17 12:15:01
| Show all posts
Since the data of each row is different in state timing, to distinguish different rows, you need to find a keyword.

private void DataGrid1_ItemDataBound_1(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//Fake code
Session["key"+key value of data, such as id as the key of Session] = e.Item.Cells[0].Text;
e.Item.Attributes.Add ("onclick","window.open('yl.aspx?ID="+ key value of data, such as id as the key of Session + "')");
}

In addition, when getting the Session, you need to pass this keyword to get the correct data without confusion.
Reply

Use magic Report

3

Threads

26

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

 Author| Post time: 2020-10-17 13:15:01
| Show all posts
The key value of the data is e.Item.Cells[0].Text, but now the value of e.Item.Cells[0].Text is not passed normally, it becomes&nbsp, how to solve it?
Reply

Use magic Report

0

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-10-17 16:30:01
| Show all posts
Try it with a click event
Reply

Use magic Report

3

Threads

26

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

 Author| Post time: 2020-10-17 16:45:01
| Show all posts
Xie Bangding upstairs, has nothing to do with the incident?
Reply

Use magic Report

0

Threads

32

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2020-10-17 17:00:01
| Show all posts
Now the value of e.Item.Cells[0].Text is not passed normally, it becomes&nbsp, how to solve it?
You print out if there is any value before saving,
private void DataGrid1_ItemDataBound_1(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
Response.Write ("<li>"+ e.Item.Cells[0].Text);

}
Reply

Use magic Report

3

Threads

26

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

 Author| Post time: 2020-10-17 17:30:01
| Show all posts
Session["LoginName"]=e.Item.Cells [0].Text; This sentence has a value when the form is loaded. When the mouse clicks, there is no value. It is null, and then the next When the page is fetched, it becomes&nbsp

Boss Meng, help me solve it, thank you
Reply

Use magic Report

1

Threads

18

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-10-17 18:00:01
| Show all posts
debug.
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-10-17 19:00:01
| Show all posts
It is recommended that the landlord determine the scope of e
Determine whether the current e object belongs to an alternate item, an edit item, or an item
Reply

Use magic Report

0

Threads

15

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-10-17 19:15:01
| Show all posts
I use the following method to open a new page when the user clicks on the DataGrid:
private void DataGrid1_ItemDataBound_1(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
e.Item.Attributes.Add ("onclick","window.open('yl.aspx?ID="+e.Item.Cells [0].Text +"')");
}
Now I don’t want to pass the value through url, I want to do it through Session:
private void DataGrid1_ItemDataBound_1(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
e.Item.Attributes.Add ("onclick","window.open('yl.aspx?')");
Session["LoginName"]=e.Item.Cells [0].Text;
}
But when I received it on another page, I found that Session["LoginName"] was a space character. What is going on?

================================================= =======

Take Session["LoginName"]=e.Item.Cells [0].Text; this line of code from the ItemDataBound event
Put it in the command event

I have used gridview before using datagrid. Just laughed

When binding data, it is executed in a loop. Assigning a value to session["LoginName"] in the loop is certainly not what you need. Prevent the command event and assign the loginName value of the current line to the session after clicking.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list