| |

VerySource

 Forgot password?
 Register
Search
View: 723|Reply: 4

GridView update button problem

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-7 09:00:01
| Show all posts |Read mode
After clicking edit, I update the contents
Then click Update, but it wo n’t update

Update button code
protected void GVeditor_RowUpdated (object sender, GridViewUpdatedEventArgs e)
    {
       try
        {
            string cj = ((TextBox) e.NewValues ​​[5]). Text; // score
            string kccj = ((TextBox) e.NewValues ​​[6]). Text; // Check results
            string xk = ((TextBox) e.NewValues ​​[1]). Text; // Student ID
            string km = ((TextBox) e.NewValues ​​[4]). Text; // subject

            string cmdtext = "update grade set grade = '" + cj + "', test grade = '" + kccj + "' where grade. student = '" + xk + "' and grade. subject in (select ID from subject where Subject.subject = '"+ km +"') ";
            SqlConnection sqlconn = new SqlConnection (sqllink.sqlconn ());
            sqlconn.Open ();

            SqlCommand sqlcomm = new SqlCommand (cmdtext, sqlconn);
            sqlcomm.ExecuteNonQuery ();
            sqlconn.Close ();
        }
        catch (Exception ex)
        {
            Response.Write (ex.Message);
        }
        this.GVeditor.DataSource = gvBind ();
        this.GVeditor.DataBind ();
        GVeditor.EditIndex = -1;
}

/////////////////////// HTML code
   <asp: GridView ID = "GVeditor" runat = "server" Width = "100%" Height = "72px" AutoGenerateColumns = "False" OnRowCancelingEdit = "GVeditor_RowCancelingEdit" OnRowEditing = "GVeditor_RowEditing" OnRowUpdating = "GVeditor_RowUpdating" OnRowUpdated = G >
                <Columns>
                    <asp: BoundField DataField = "Student Number" HeaderText = "Student Number" ReadOnly = "True" />
                    <asp: BoundField DataField = "Class" HeaderText = "Class" ReadOnly = "True" />
                    <asp: BoundField DataField = "Name" HeaderText = "Name" ReadOnly = "True" />
                    <asp: BoundField DataField = "Subject" HeaderText = "Subject" ReadOnly = "True" />
                    <asp: TemplateField HeaderText = "grades">
                        <EditItemTemplate>
                            <asp: TextBox ID = "TextBox1" runat = "server" Text = '<% # Eval ("grade")%>'> </ asp: TextBox>
                        </ EditItemTemplate>
                        <ItemTemplate>
                            <asp: Label ID = "Label3" runat = "server" Text = '<% # Eval ("achievement")%>'> </ asp: Label>
                        </ ItemTemplate>
                    </ asp: TemplateField>
                    <asp: TemplateField HeaderText = "Test results">
                        <EditItemTemplate>
                            <asp: TextBox ID = "TextBox2" Text = '<% # Eval ("Exam results")%>' runat = "server"> </ asp: TextBox>
                        </ EditItemTemplate>
                        <ItemTemplate>
                            <asp: Label ID = "Label4" runat = "server" Text = '<% # Eval ("Exam results")%>'> </ asp: Label>
                        </ ItemTemplate>
                    </ asp: TemplateField>
                    <asp: CommandField ShowEditButton = "True"> </ asp: CommandField>
                </ Columns>
           </ asp: GridView>
        
Thanks guys
Reply

Use magic Report

0

Threads

32

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2020-5-24 10:30:01
| Show all posts
GVeditor_RowUpdated?
The code is written in
GVeditor_RowUpdating event
Reply

Use magic Report

0

Threads

8

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-5-24 13:00:01
| Show all posts
Do you confirm that the database has not been updated? Or did you not rebind?
The event is not correct?
Reply

Use magic Report

3

Threads

29

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-5-25 19:45:02
| Show all posts
(1) The timing of the update is incorrect, and your event can only be triggered after it is updated.
(2) Update without writing code, bind SqlDataSource, and write its Update statement. Note that the parameter that takes the original value uses @original_field name, the new value takes @field name, and the OldParametersFormat property is set to @original_ {0 }
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-7-24 20:15:01
| Show all posts
I'll go see first
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