我正在使用GridView
,並已綁定到SQL使用asp.net的前端。在button_Click之前,我確保重置了與GridView
綁定的我的數據庫表的值,但它沒有反映在button_Click之後的GridView
中。如何刷新GridView與數據庫綁定數據時使用asp.net c#
這裏是GridView
我的ASP代碼:
<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();
非常感謝你...它的作品:) –
不客氣.. :) –