+ -
当前位置:首页 → 问答吧 → asp.net gridview 代码绑定数据,在页面里往数据库添加一条记录,直接在gridview里显示出来!跪求。。

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();
  }






作者: zhangdian4444   发布时间: 2011-11-27

自己顶

作者: zhangdian4444   发布时间: 2011-11-27

现在的情况是点击回复该帖子之后,再点击该帖子才能把新添加的一条回复显示出来。刷新都不行~求解

作者: zhangdian4444   发布时间: 2011-11-27

分不多了,求大神指教啊~~~

作者: zhangdian4444   发布时间: 2011-11-27