0

GridViewasp.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();   
4

3 に答える 3

1

grdFoo.DataBind()あなたのbutton_Clickイベントを呼び出します。

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();   
      // Call DataGrid's bind method here..for example
      grdFoo.DataBind()
}
于 2012-09-10T10:45:20.320 に答える
0

Mayakで示されているように、データを更新して再度バインドする必要があります。または、更新パネルを使用して、データを更新して再度バインドすることもできますgridview

于 2012-09-10T10:57:08.337 に答える
0

GridView の DataBind メソッドを呼び出して、グリッドを更新できます。

于 2012-09-10T10:43:10.263 に答える