我在按钮单击时显示了gridview上的所有数据,并且我在gridview中启用填充在网格视图上显示,但是当我单击网格填充(如12345)时,则在网格视图上不显示值之后... [英] i show all data on gridview on the button click and i enable padding in gridview data is show on grid view but when i click on grid pading (like 12345) then after value is not show on grid view...

查看:52
本文介绍了我在按钮单击时显示了gridview上的所有数据,并且我在gridview中启用填充在网格视图上显示,但是当我单击网格填充(如12345)时,则在网格视图上不显示值之后...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击按钮后我会在网格视图上显示所有数据,并在网格视图中启用填充,但数据会在网格视图上显示,但是当我单击网格填充(如12345)时,则在网格视图上不显示值.
我现在该怎么办?

我使用这些代码:

I show all data on grid view on the button click and I enable padding in grid view data is show on grid view but when i click on grid padding (like 12345) then after value is not show on grid view.
What should i do now?

I use these code :

<div>
   <table class="style1">
           <tr><td class="style4" width="156px">Find a Class</td>
               <td align="center" class="style5">
                   <asp:DropDownList ID="DropDownList2" runat="server">
                       <asp:ListItem>Select Class</asp:ListItem>
                       <asp:ListItem>Language Class English</asp:ListItem>
                       <asp:ListItem>Music Class</asp:ListItem>
                       <asp:ListItem>Baby Sitters</asp:ListItem>
                       <asp:ListItem>Skating Classes</asp:ListItem>
                       <asp:ListItem>Yoga Class</asp:ListItem>
                       <asp:ListItem>Swimming Class</asp:ListItem>
                       <asp:ListItem>Chess Class</asp:ListItem>
                       <asp:ListItem>Self Defence Classes</asp:ListItem>
                       <asp:ListItem>Tennis Classes</asp:ListItem>
                       <asp:ListItem>Personality Development For Children</asp:ListItem>
                       <asp:ListItem>Martial Art Training Centres</asp:ListItem>
                       <asp:ListItem>Karate Classes</asp:ListItem>
                       <asp:ListItem>Cricket Coaching Classes</asp:ListItem>
                       <asp:ListItem>Schools</asp:ListItem>
                       <asp:ListItem>Computer Training Institutes</asp:ListItem>
                       <asp:ListItem>Aerobic Classes</asp:ListItem>
                       <asp:ListItem>Badminton Court</asp:ListItem>
                       <asp:ListItem>Kick Boxing Classes</asp:ListItem>
                       <asp:ListItem>Abacus Classes</asp:ListItem>
                       <asp:ListItem>Kindergartens</asp:ListItem>
                       <asp:ListItem>Hobby Classes</asp:ListItem>
                       <asp:ListItem>Kung FU Classes</asp:ListItem>
                       <asp:ListItem>Taekwondo Class</asp:ListItem>
                       <asp:ListItem>Summer Camps</asp:ListItem>
                       <asp:ListItem>Dance Classes</asp:ListItem>
                   </asp:DropDownList>
               </td><td align="center" width="100px">

                       <asp:DropDownList ID="DropDownList3" runat="server"

                           >
                           <asp:ListItem>Noida</asp:ListItem>
                           <asp:ListItem>Indirapuram</asp:ListItem>
                           <asp:ListItem>Vaishali</asp:ListItem>
                           <asp:ListItem>Vasundhara</asp:ListItem>
                           <asp:ListItem>Sahibabad</asp:ListItem>
                           <asp:ListItem>Kaushambi</asp:ListItem>
                       </asp:DropDownList>

               </td>
               <td align="center" class="style2" width="100px">
                   <asp:Button ID="Button1" runat="server"  Text="GO" onclick="Button1_Click"

                       Height="31px" Width="71px" BackColor="#B9B9B9" BorderStyle="None" />
                   &nbsp;</td>
           </tr>
          <tr><td class="style4" colspan="4">
              &nbsp;</td>
                   </tr>
           <tr>
               <%--<asp:Panel ID="Panel2" runat="server" Visible="False">
                <td class="style4">
               <asp:Label ID="Label1" runat="server" Text="InSector"></asp:Label>
           </td>
           <td>

           </td>
           <td>

            </td>
               </asp:Panel>--%>

           </tr>


           </table>
   </div>
       <asp:GridView ID="GridView1" runat="server" Width="614px" AllowPaging="True"

           onpageindexchanging="GridView1_PageIndexChanging1">
       </asp:GridView>


这是C#代码:


This is c# code :

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    SqlConnection con;
    SqlCommand cmd;
    DataSet ds;
    string connection;
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source=RESTON-PC;Initial Catalog=Easy2Connect;Integrated Security=True");

        con.Open();
        string ret = "select * from SearchData where ClassName = '" + DropDownList2.SelectedItem + "'and City = '" + DropDownList3.SelectedItem + "'";
        cmd = new SqlCommand(ret, con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        con.Close();
    }
   
    protected void GridView1_PageIndexChanging1(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }
}


请帮助我.


Please help me.

推荐答案

protected void GridView1_PageIndexChanging1(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSource = ds //<-- This line is missing. There is no datasource being set on Page changing event.
        GridView1.DataBind();
    }



您可以将数据源保存在变量中,这样就不必重复代码即可重新填充数据源:



You can hold the data source in a variable so that you don''t have to duplicate code to re populate the data source:

private DataSet GridView1DataSource
{
  get
  {
    if(Session["gridview1datasource"] == null)
    {
      Session["gridview1datasource"] = new DataSet;
    }
    return (DataSet)Session["gridview1datasource"];
  }
  set
  {
    Session["gridview1datasource"] = value;
  }
}



然后将Button1_Click更改如下:



Then change the Button1_Click to be as follows:

protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source=RESTON-PC;Initial Catalog=Easy2Connect;Integrated Security=True");
 
        con.Open();
        string ret = "select * from SearchData where ClassName = ''" + DropDownList2.SelectedItem + "''and City = ''" + DropDownList3.SelectedItem + "''";
        cmd = new SqlCommand(ret, con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        //DataSet ds = new DataSet(); <-- Don''t need this line now as the DS is created by the GridView1DataSource property.
        da.Fill(GridView1DataSource); //<-- change this to use the session variable.
        GridView1.DataSource = ds;
        GridView1.DataBind();
        con.Close();
    }



一切顺利.



All the best.


这篇关于我在按钮单击时显示了gridview上的所有数据,并且我在gridview中启用填充在网格视图上显示,但是当我单击网格填充(如12345)时,则在网格视图上不显示值之后...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆