Hi!
I have a problem. I cannot update the row in GridView control.

<asp:Label ID="Label1" runat="server" Text="Username: "></asp:Label><asp:TextBox
                                ID="unTextBox" runat="server"></asp:TextBox><%--<asp:RequiredFieldValidator ID="usernameRequiredFieldValidator"
                                    runat="server" ErrorMessage="*" ControlToValidate="unTextBox"></asp:RequiredFieldValidator>--%><asp:Button ID="unSearchButton" runat="server"
                                    Text="Search"/><br /><br />
                            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="MySqlDataSource" CellPadding="4" ForeColor="#333333" Font-Size="Small">
                                <Columns>
                                    <asp:CommandField ShowEditButton="True" />
                                    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" ReadOnly="true" />
                                    <asp:BoundField DataField="Last_Name" HeaderText="Last Name" SortExpression="Last_Name" ReadOnly="true" />
                                    <asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" ReadOnly="true" />
                                    <asp:BoundField DataField="Email" HeaderText="E-mail" SortExpression="Email" ReadOnly="true" />
                                    <asp:CheckBoxField DataField="IsApproved" HeaderText="User Approved?" SortExpression="IsApproved" />
                                </Columns>
                                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                <EditRowStyle BackColor="#999999" />
                                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                            </asp:GridView>
                            <asp:SqlDataSource ID="MySqlDataSource" runat="server" ConnectionString="server=servername;user id=userid;Password=password;database=dbname;persist security info=True" ProviderName="MySql.Data.MySqlClient" SelectCommand="SELECT p.Name, p.Last_Name, u.Username, u.Email, u.IsApproved FROM users u INNER JOIN person p ON u.PERSON_REF = p.ID WHERE u.IsApproved=0" UpdateCommand="UPDATE users SET IsApproved=?IsApproved WHERE Username=?Username " >
                            <%--<SelectParameters><asp:ControlParameter ControlID="unTextBox" Name="Username" PropertyName="Text" /></SelectParameters>--%>
                            <UpdateParameters><asp:Parameter Type="Int16" Name="IsApproved"/><asp:Parameter Type="String" Name="Username" /></UpdateParameters></asp:SqlDataSource>

When I try edit and check the checkbox in User Approved field and then click the Update it doesn't not update the field. What am I doing wrong?

Recommended Answers

All 2 Replies

Hi Donish,

I don't know if you solved the problem, but here is my suggestion.
I don't see any code to update the GridView. I mean, there is an UpdateCommand in the DataSource, but in the GridView there's nothing saying to actually perform the update. Do you have any code in the code behind? If so, please post. =)
Where are you getting the value of the CheckBox? How are you editing the row?
What I suggest for now is to add an <EditItemTemplate> to your GridView. I think it's a easy way to edit the gridView.

If you have any questions (or if you solved the problem already) let us know.

Ana

do u have any primary key in ur table...?

if yes then get back 2 me...asap..

i think i have the solution..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.