asp.net gridview 代码绑定数据,在页面里往数据库添加一条记录,直接在gridview里显示出来!跪求。。
时间:2011-11-27
来源:互联网
<asp:GridView ID="GridView2" runat="server" AllowPaging="True"
AutoGenerateColumns="False" GridLines="None" OnRowCreated="gvMain_RowCreated"
BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px"
CellPadding="4" Width="977px"
OnPageIndexChanging="GridView1_PageIndexChanging" Height="16px"
PageSize="9" onselectedindexchanged="GridView2_SelectedIndexChanged1"
>
<FooterStyle BackColor="White" ForeColor="#333333" />
<Columns>
<asp:TemplateField >
<ItemTemplate >
<asp:Image ID="Image1" runat="server" ImageUrl="~/bbs/bbspic/nimingtouxiang.jpg" />
</ItemTemplate>
<HeaderStyle BackColor="White" />
</asp:TemplateField>
<asp:BoundField DataField="body" SortExpression="body" >
<HeaderStyle BackColor="White" />
</asp:BoundField>
<asp:BoundField DataField="data" SortExpression="data" >
<HeaderStyle BackColor="White" />
</asp:BoundField>
</Columns>
<RowStyle ForeColor="#333333" BackColor="White" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True"
ForeColor="White" />
<PagerStyle BackColor="#336666" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#336666" Font-Bold="True"
ForeColor="White" />
</asp:GridView>
public void show()
{
myCommand.CommandText = "select body,data from tiezifabiao where bbszhujian='" +Request.QueryString["zhujian"] + "' ";
SqlDataAdapter myDataAdapter = new SqlDataAdapter();
myDataAdapter.SelectCommand = myCommand;
DataSet mySet = new DataSet();
myDataAdapter.Fill(mySet, "Student");
GridView2.DataSource = mySet;
GridView2.DataBind();
myConnection.Close();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView2.PageIndex = e.NewPageIndex;
GridView2.DataBind();
show();
}
AutoGenerateColumns="False" GridLines="None" OnRowCreated="gvMain_RowCreated"
BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px"
CellPadding="4" Width="977px"
OnPageIndexChanging="GridView1_PageIndexChanging" Height="16px"
PageSize="9" onselectedindexchanged="GridView2_SelectedIndexChanged1"
>
<FooterStyle BackColor="White" ForeColor="#333333" />
<Columns>
<asp:TemplateField >
<ItemTemplate >
<asp:Image ID="Image1" runat="server" ImageUrl="~/bbs/bbspic/nimingtouxiang.jpg" />
</ItemTemplate>
<HeaderStyle BackColor="White" />
</asp:TemplateField>
<asp:BoundField DataField="body" SortExpression="body" >
<HeaderStyle BackColor="White" />
</asp:BoundField>
<asp:BoundField DataField="data" SortExpression="data" >
<HeaderStyle BackColor="White" />
</asp:BoundField>
</Columns>
<RowStyle ForeColor="#333333" BackColor="White" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True"
ForeColor="White" />
<PagerStyle BackColor="#336666" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#336666" Font-Bold="True"
ForeColor="White" />
</asp:GridView>
public void show()
{
myCommand.CommandText = "select body,data from tiezifabiao where bbszhujian='" +Request.QueryString["zhujian"] + "' ";
SqlDataAdapter myDataAdapter = new SqlDataAdapter();
myDataAdapter.SelectCommand = myCommand;
DataSet mySet = new DataSet();
myDataAdapter.Fill(mySet, "Student");
GridView2.DataSource = mySet;
GridView2.DataBind();
myConnection.Close();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView2.PageIndex = e.NewPageIndex;
GridView2.DataBind();
show();
}
作者: zhangdian4444 发布时间: 2011-11-27
自己顶
作者: zhangdian4444 发布时间: 2011-11-27
现在的情况是点击回复该帖子之后,再点击该帖子才能把新添加的一条回复显示出来。刷新都不行~求解
作者: zhangdian4444 发布时间: 2011-11-27
分不多了,求大神指教啊~~~
作者: zhangdian4444 发布时间: 2011-11-27
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28