我正在使用GridView
并已使用 asp.net 在前端绑定到 SQL。在 button_Click 之前,我确保绑定到的我的数据库表的值GridView
被重置,但它没有反映在GridView
button_Click 之后。
这是我的asp代码GridView
:
<Columns>
<asp:BoundField DataField="Profiles" HeaderText="Profiles" ReadOnly="true" SortExpression="Profiles" />
<asp:BoundField DataField="Location_Profile" HeaderText="Location_Profile" SortExpression="Location_Profile" />
</Columns>
数据源asp代码为:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TouchPadConnectionString %>"
InsertCommand="INSERT INTO [Loc_Pro_Grid] ([Profiles], [Location_Profile]) VALUES (@Profiles, @Location_Profile)"
SelectCommand="SELECT * FROM [Loc_Pro_Grid]"
UpdateCommand="UPDATE Loc_Pro_Grid SET Location_Profile = @Location_Profile WHERE (Profiles = @Profiles)">
<InsertParameters>
<asp:Parameter Name="Profiles" Type="String" />
<asp:Parameter Name="Location_Profile" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Location_Profile" />
<asp:Parameter Name="Profiles" />
</UpdateParameters>
</asp:SqlDataSource>
我的 .cs 代码是:
protected void Save_Click(object sender, EventArgs e)
{
// I am doing some operations here then I am resetting the table as below
com = new SqlCommand("UPDATE Loc_Pro_Grid SET Location_Profile = 0 WHERE Profiles='" + ListBox1.Items[i].ToString() + "' ", con);
}
con.Open();
com.ExecuteNonQuery();
con.Close();