| |

VerySource

 Forgot password?
 Register
Search
View: 4887|Reply: 39

A little fun question!

[Copy link]

2

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-1-25 03:20:01
| Show all posts |Read mode
A SqlDataSource, its select insert update delete is set.
Put another gridview
If you set the data source of the GridView through smart tags in the design state: SqlDataSource1. After the program runs, everything works fine. You can perform the above four operations.
However, in the setting state, the data source is not set for the GridView, but is set in the program: Page_Load.
GridView1. DataSource = SqlDataSource1;
GridView1. DataBind ();

Well. Data will not be updated.

Excuse me, why? If I write the binding in other events, how can I see the data every time I refresh the page?
Reply

Use magic Report

0

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-2-13 10:45:01
| Show all posts
Are the parameters set?
Reply

Use magic Report

0

Threads

43

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-2-13 11:45:01
| Show all posts
Page_Load binds the data source. You need to write update code and rebind after the update.
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-14 09:45:01
| Show all posts
If you want to bind the gridview in the background and update and delete the relevant code, you cannot use it directly. Provide a delete operation.
protected void GridView1_RowDeleting (object sender, GridViewDeleteEventArgs e)
    {
        int index = e.RowIndex;
        int LogID = (int) GridView1.DataKeys [index] .Value; // take the primary key
        Use this primary key for operations
    }
Reply

Use magic Report

0

Threads

18

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-2-15 14:30:01
| Show all posts
After working for a long time, but did not figure out the final result, some findings:
To bind the data source of the GridView in the background and update it,
To implement the GridView event OnRowEditing, it will not report an error after adding it, but there is no editing function.
To edit, I guess I have to handle it in the OnRowDataBound event of the GridView.
Add the TextBox or something manually, and then bind the data.
Limited ability, look forward to expert guidance.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-4 11:15:01
| Show all posts
Put it under the Page_PreInit event
Reply

Use magic Report

2

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-3-10 12:30:01
| Show all posts
My method is stupid. I can only say that it is implemented, but I don't think it is scientific: that is, manually writing the update code.
Use edittemplate, then when the update operation, manually get the control value, and then use sqldatasource.updata to update.
It's just that stupid.

I can't figure out why program binding is different from design state binding.
Reply

Use magic Report

0

Threads

34

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-3-11 17:45:01
| Show all posts
On the button?
Reply

Use magic Report

0

Threads

5

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-12 07:15:01
| Show all posts
Do you want to select the AllowEdit checkbox and write an OnRowUpdating event!
Reply

Use magic Report

0

Threads

64

Posts

45.00

Credits

Newbie

Rank: 1

Credits
45.00

 China

Post time: 2020-3-12 17:45:01
| Show all posts
GridView1.DataSourceID = SqlDataSource1;
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