我在更新面板中的网格未刷新 [英] MY GRID IN THE UPDATE PANEL IS NOT REFRESHING
本文介绍了我在更新面板中的网格未刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网格,应该在将新数据插入其中后对其进行刷新,为此我使用了更新面板,但是问题是单击事件后更新面板没有刷新.
Hi,
I have an gird which should refresh after a new data is being inserted into it,for which i used the update panel,but the problem is the update panel is not refreshing after the click event.
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<p>
</p>
<p><asp:ScriptManager ID="MainScriptManager" runat="server" />
<asp:UpdatePanel ID="pnlHelloWorld" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="username" HeaderText="username"
SortExpression="username" />
<asp:BoundField DataField="comments" HeaderText="comments"
SortExpression="comments" />
</Columns>
</asp:GridView>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
style="position: relative; top: 0px; left: 0px; width: 379px" Text="Button"
/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button2" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
我的点击事件背后的代码:
my code behind click event:
protected void Button2_Click(object sender, EventArgs e)
{
string username = TextBox1.Text;
string comments = TextBox2.Text;
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["ForumDBConnectionString"].ConnectionString);//create our sql command object
SqlCommand cmd = new SqlCommand("Insert INTO tests(username,comments) VALUES (@username, @comments)", conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@username", username);
cmd.Parameters.AddWithValue("@comments", comments);
using (conn)
{
conn.Open();
cmd.ExecuteNonQuery();
}
请帮助我
pls help me out
推荐答案
在插入值后绑定网格
Bind your grid after inserting value
using (conn)
{
conn.Open();
cmd.ExecuteNonQuery();
gridview1.DataBind();
}
这篇关于我在更新面板中的网格未刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文