分页在GridView中不支持 [英] paging is not supporting in gridview

查看:65
本文介绍了分页在GridView中不支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
每当我将分页应用于gridview时,我都会遇到问题.每当我使用连接的体系结构时,都会抛出异常,表明sqldatareader不支持服务器端分页,当我使用断开的体系结构时,它工作正常,但是我想要存储过程中的数据,我不知道在断开连接的体系结构中使用它,因此我将其与下面的代码一起使用,它会抛出System.ArgumentOutOfRangeException:指定的参数不在有效值范围内.请帮助我.

预先感谢

.aspx代码

hello
i''m facing problem whenever i''m applying paging to the gridview.whenever i''m using connected architecture it is throwing exception saying that sqldatareader doesnot support server side paging and when i used disconnected architecture it is working fine but i want the data from stored procedure and i have no idea of using it in dissconnected architecture so i use it with the below code there it is throwing System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.plz help me.

thanx in advance

.aspx code

<<form id="form1"  runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
          
        <asp:Timer ID="Timer1" runat="server" Interval="10000555" OnTick="Timer1_Tick">
        </asp:Timer>
                               
              <span style="font-size: 24pt; color: #00cc33; font-family: Garamond">
            </span><asp:GridView ID="GridView1" runat="server" AllowPaging="true" EmptyDataText="there is no data" Height="100%" OnPageIndexChanged="GridView1_PageIndexChanged" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="150" Width="100%" style="padding:0px;margin:0px" OnRowDataBound="GridView1_RowDataBound" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AutoGenerateColumns="False" AllowPaging="True">
            <RowStyle Font-Names="Cambria" Font-Size="Large" HorizontalAlign="Left" VerticalAlign="Middle" />
            <HeaderStyle Height="10px" BackColor="Black" ForeColor="White" HorizontalAlign="Left" VerticalAlign="Middle" Font-Names="Cambria" Font-Size="Larger" Wrap="True" />
        <Columns>
        <asp:BoundField DataField="s_TicketNo" HeaderText="TicketNo" />
            <asp:BoundField DataField="s_CustomerName" HeaderText="CustomerName" />
            <asp:BoundField DataField="s_Model" HeaderText="Model " />
            <asp:BoundField DataField="s_WorkOrderType" HeaderText="WorkOrderType" />
            <asp:BoundField DataField="CallDate" HeaderText="CallDate" />
            <asp:BoundField DataField="Currentstatus" HeaderText="Currentstatus" />
            <asp:BoundField DataField="s_BranchCode" HeaderText="BranchCode" />
            <asp:BoundField DataField="PendingFor" HeaderText="PendingFor" />
            <asp:BoundField DataField="Color" HeaderText="Color" >
                <FooterStyle CssClass="sss" />
                <HeaderStyle CssClass="sss" />
               <ItemStyle CssClass="sss" />
                                    
        </asp:BoundField>
        </Columns>
        
        </asp:GridView>
         
    </div>
    </form>


.aspx.cs代码


.aspx.cs code

protected void Page_Load(object sender, EventArgs e)
    {
     
    
            getData();
    }
    public SqlDataReader BindData()
    {


        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["UNIVolvo"].ConnectionString);

        SqlCommand cmd = new SqlCommand("usp_DashboardDetails", con);
        cmd.CommandType = CommandType.StoredProcedure;
        con.Open();
        SqlDataReader sdr = cmd.ExecuteReader();
        
        return sdr;
        //    GridView1.DataSource = dr;
          //  GridView1.DataBind();
              
         
    }
    public void getData()
    {
       
        GridView1.DataSource = BindData();
        GridView1.DataBind();
    }

    
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        getData();
    }
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        BindData();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        string strcolor = e.Row.Cells[8].Text;
        if (strcolor == "Orange")
            e.Row.BackColor = System.Drawing.Color.Orange;
        else if (strcolor == "Green")
            e.Row.BackColor = System.Drawing.Color.Green;
    
    }

推荐答案


您没有创建网格AllowPaging="True"

Hi ,
You didn''t make your Grid AllowPaging="True"

<asp:gridview id="GridView1" runat="server" emptydatatext="there is no data" height="100%" onpageindexchanged="GridView1_PageIndexChanged" onpageindexchanging="GridView1_PageIndexChanging" pagesize="150" width="100%" style="padding:0px;margin:0px" onrowdatabound="GridView1_RowDataBound" onselectedindexchanged="GridView1_SelectedIndexChanged" autogeneratecolumns="False" allowpaging="True" xmlns:asp="#unknown"></asp:gridview>


最好的问候
M.Mitwalli


Best Regards
M.Mitwalli


取消命令BindData方法中存在的Gridview Bind语句,并在getData的状态下使用BindData方法.
之所以显示此异常,是因为在读取器的范围之外使用了读取器的值.
Uncommand the Gridview Bind statement present in the BindData method and use BindData method in the instate of getData .

This Exception is showing because the value of the reader is used outside the range of the reader.


就在行数据绑定事件中,我们需要添加以下代码.我们需要添加以下代码代码.
just in the row databound event we need to add the following code.we need to add this following code.
if (e.Row.RowType == DataControlRowType.DataRow)
        
{
}
if (e.Row.RowType == DataControlRowType.DataRow)      {
            string strcolor = e.Row.Cells[8].Text;
            if (strcolor == &quot;Orange&quot;)
                e.Row.BackColor = System.Drawing.Color.Orange;
            else if (strcolor == &quot;Green&quot;)
                e.Row.BackColor = System.Drawing.Color.Green;
            else if(strcolor==&quot;Red&quot;)
                e.Row.BackColor = System.Drawing.Color.Red;
        }


这篇关于分页在GridView中不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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