首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET Framework >

listview数据绑定的有关问题

2012-12-20 
listview数据绑定的问题!现在有一个表,它就一列,这一列用于放日期,现在存有两个日期,一个是2010.1.10,一个

listview数据绑定的问题!
现在有一个表,它就一列,这一列用于放日期,现在存有两个日期,一个是2010.1.10,一个是2010.2.10,在初始的情况下,我为其查出这个数据,查出来的结果在页面中是以日期的升序显示的,第一条是2010.1.10,第二条是2010.2.10;此时我选择降序排序,它会重新绑定数据,通过调试发现,查出来的数据确实第一条是2010.2.10,第二是2010.1.10,但是在页面是显示的时候为什么还是和刚才一样呢?第一条显示2010.1.10,第二条显示2010.2.10。还请各位告知,谢谢!
[解决办法]
贴你的代码上来.

是否有
if(!Page.IsPostBack)
{
  
}

绑定方法是否调错了。
[解决办法]
页面:


 <ext:ContentPanel ID="ContentPanel1" runat="server" ShowBorder="false" ShowHeader="false"
                EnableBackgroundColor="true" BodyPadding="0px" CssStyle="margin-top:0px;padding-top:0px; text-align:center"
                Width="900px">
                    &nbsp;&nbsp;<table  cellpadding='0' cellspacing='0' width='850px' id="table1"> 
                                         <tr id="Tr4" runat="server">
                                            <td id="Td7adsf" runat="server">
                                             <ext:Toolbar runat="server"  ID="toolbar" Height="25px" CssStyle="margin-top:3px;">
                                                    <Items>
                                                        <ext:Button ID="btnAdd" Text="新增到款" runat="server"  CssStyle="margin-right:530px;" />
                                                           <ext:ToolbarText ID="ToolbarText1" Text="排序方式:" runat="server" />
                                                         <ext:DropDownList ID="ddLSort" runat="server" Label="排序方式:"  CssStyle="margin-top:5px;"   OnSelectedIndexChanged="ddLSort_SelectedIndexChanged"  AutoPostBack="true"></ext:DropDownList>


                                                    </Items>
                                                </ext:Toolbar>
                                            </td>
                                            </tr>
                                            </table>
                  <asp:ListView ID="ListView1" runat="server">
                            <LayoutTemplate>
                                 <table  cellpadding='0' cellspacing='0' width='850px' id="table1"> 
                                         <tr runat="server">
                                             <td style="height:3px;">
                                            </td>
                                         </tr>
                                         <tr id="Tr1" runat="server">
                                            <th id="Th1" runat="server" style="text-align:left; font-size:110%; font-weight:bold;" >客户名称</th>
                                             <th id="Th11" runat="server" style="text-align:left; font-size:110%; font-weight:bold;">单号</th>


                                            <th id="Th2" runat="server" style="text-align:left; font-size:110%; font-weight:bold;">金额(元)</th>
                                            <th id="Th3" runat="server" style="text-align:left; font-size:110%; font-weight:bold;">类型</th>
                                            <th id="Th4" runat="server" style="text-align:left; font-size:110%; font-weight:bold;">实际到款日期</th>
                                            <th id="Th6" runat="server" style="text-align:left; font-size:110%; font-weight:bold;">余额(元)</th>
                                             <th id="Th7" runat="server" style="text-align:left; font-size:110%; font-weight:bold;">核销情况</th>
                                            <th id="Th8" runat="server" style="text-align:left; font-size:110%; font-weight:bold;">是否冲红</th>
                                            <th id="Th10" runat="server" style="text-align:left; font-size:110%; font-weight:bold;">操作</th>
                                         </tr>
                                        <tr id="Tr2" runat="server" >
                                            <td id="Td1" colspan="9" runat="server">
                                                <hr  style=" border:1px #d9deea solid;"/>
                                            </td>


                                        </tr>
                                         <tr runat="server" id="itemPlaceholder" ></tr>  
                                         <tr runat="server" >
                                            <td colspan="9" runat="server" align="center" >
                                                 <asp:DataPager runat="server" ID="DataPager" PageSize="5">
      <Fields>
          <asp:nextpreviouspagerfield FirstPageText="第一页" LastPageText="最后一页" 
                NextPageText="下一页" PreviousPageText="上一页" />
      </Fields>
    </asp:DataPager> 
                                            </td>
                                         </tr>
                                 </table>                              
                                  

                            </LayoutTemplate>
                            <ItemTemplate >
                               
                                <tr id="Tr3" runat="server">
                                    <td id="Td2" runat="server" align="left" style="width:20%;">


                      
                                       <ext:HyperLink ID="hlkCustomer" runat="server" NavigateUrl="" Target="_blank" ShowLabel="false" Text='<%#Eval("Customer_FullName")%>' />
                                    </td>
                                      <td id="Td6" runat="server" align="left" style="width:12%;">
                                       <ext:HyperLink ID="hlkPayedFundCode" runat="server" NavigateUrl="" Target="_blank" ShowLabel="false" Text='<%#Eval("PayedFund_Code")%>'  />
                                    </td>
                                    <td id="Td3" runat="server" align="left" style="width:12%;">
                                       <span  style=" color:Red; font-weight:bold;"><%#Eval("PayedFund_AmountFormat")%></span>
                                    </td>
                                    <td id="Td4" runat="server" align="left" style="width:6%;">
                                         <%#Eval("PayedFundBillType")%>
                                       
                                    </td>
                                      <td id="Td31" runat="server" align="left" style="width:10%;">
                                       <%#Eval("PayedFund_PayedDateFormat")%>


                                    </td>
                                 <td runat="server" align="left" style="width:12%;">
                                    <span  style=" color:Red; font-weight:bold;"><%#Eval("PayedFund_LeftAmountFormat")%></span>
                                    </td>
                                    <td  runat="server" align="left" style="width:8%;">
                                        <%#Eval("PayedFund_VerifyCount")%>
                                    </td>  <td  runat="server" align="lelt" style="width:6%;">
                                       <%#Eval("PayedFund_IfCancel")%>
                                    </td>
                                   
                                    <td id="Td5" runat="server" align="left" style="width:4%;">
                                        
                                        <asp:LinkButton ID="lbVerify" runat="server" Text="核销"  CommandName="verify"/> <br />
                                        <asp:LinkButton ID="lbCancel" runat="server" Text="冲红" />
                                    </td>


                                   
                                    
                                </tr> 
                                 <tr id="Traf4" runat="server">
                                    <td id="Td8" runat="server" colspan="9">
                                           <hr  style=" border:1px #d9deea solid;"/>
                                    </td>
                                </tr>
                            </ItemTemplate>
                           <EmptyDataTemplate>
                                <tr runat="server">
                                    <td colspan="9">暂无到款信息</td>
                                </tr>
                           </EmptyDataTemplate>
                        </asp:ListView>
            </ext:ContentPanel>


[解决办法]
后台代码:

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
               


                this.BindListView(-1);
                this.BindSort();
              
            }
       }

              /// <summary>
        /// 绑定排序选项
        /// </summary>
        protected void BindSort()
        {
          
            //新建下拉选项
            ExtAspNet.ListItem lt = new ExtAspNet.ListItem();
            lt.Text = "默认";
            lt.Value = "0";
            ddLSort.Items.Add(lt);
            lt = new ExtAspNet.ListItem();
            lt.Text = "单号";
            lt.Value = "1";
            ddLSort.Items.Add(lt);
            lt = new ExtAspNet.ListItem();
            lt.Text = "客户名称";
            lt.Value = "2";
            ddLSort.Items.Add(lt);
            lt = new ExtAspNet.ListItem();
            lt.Text = "实际到款日期";
            lt.Value = "3";
            ddLSort.Items.Add(lt);
            lt = new ExtAspNet.ListItem();
            lt.Text = "凭证到达日期";
            lt.Value = "4";
            ddLSort.Items.Add(lt);
            //选定默认项
            for (int i = 0; i < ddLSort.Items.Count; i++)
            {
                if (ddLSort.Items[i].Text == "默认")
                {
                    ddLSort.Items[i].Selected = true;
                }


            }
        }

        /// <summary>
        /// 绑定到款信息
        /// </summary>
        /// <param name="sort">排序的方式,如为-1,则为默认排序</param>
        protected void BindListView(int sort)
        {
            //定义并获取查询语句
            string swhere = getSearchSql();
            //获取排序方式
            swhere += GetSort(sort);
            DataTable dt = tbBKPayedFund_BLLSub.GettbBKPayedFundByNoRefAllByFilte(swhere);
            this.ListView1.DataSource = dt;
            this.ListView1.DataBind();
           
        }
        #region 可区域可复用方法

        /// <summary>
        /// 获取查询语句
        /// </summary>
        /// <returns></returns>
        protected string getSearchSql()
        {
            string swhere = " 1=1 ";
            //获取客户名称
            if (this.tbCustomerName.Text != "")
            {
                swhere += " and  Customer_FullName like '%" + tbCustomerName.Text + "%' ";
            }
                      //返回查询sql语句
            return swhere;
        }

        /// <summary>
        /// 获取排序语句
        /// </summary>
        /// <param name="sort">排序种类</param>
        /// <returns>排序语句</returns>
        protected string GetSort(int sort)
        {

            string sortsql = "";
            //判断排序的值并分配相应的排序语句
            switch (sort)


            {
                case 0:
                    sortsql = " order by PayedFund_Code desc,PayedFund_CustomerID desc ";
                    break;
                case 1:
                    sortsql = " order by PayedFund_Code desc";
                    break;
                case 2:
                    sortsql = " order by PayedFund_CustomerID desc";
                    break;
                case 3:
                    sortsql = " order by PayedFund_PayedDate desc";
                    break;
                case 4:
                    sortsql = " order by PayedFund_AdvanceVoucherReachTime desc";
                    break;
                default:
                    sortsql = " order by PayedFund_Code desc,PayedFund_CustomerID desc ";
                    break;
            }
            //返回
            return sortsql;

        }

        #endregion

        /// <summary>
        /// 排序方式改变响应
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddLSort_SelectedIndexChanged(object sender, EventArgs e)
        {
            //将之前为listview绑定的数据清空
            ListView1.DataSource = null;


            ListView1.DataBind();
            int sort = Convert.ToInt32(this.ddLSort.SelectedValue);
            //重新绑定数据
            this.BindListView(sort);
        }


[解决办法]
其中排序方式改变响应方法中的三行代码:
//将之前为listview绑定的数据清空
            ListView1.DataSource = null;
            ListView1.DataBind();

是我后来加上的,但也不行。
[解决办法]
太长了吧,都没兴趣看下去了....
要简短,易懂。才会有人看///
[解决办法]
高手会觉得浪费自己的时间
像我们这样的又没看不懂
[解决办法]
引用:
高手会觉得浪费自己的时间
像我们这样的又没看不懂

看不懂可以漫漫看嘛。。
[解决办法]
帮顶
[解决办法]
我也在做这类似的,帮顶UP!高手呢?
[解决办法]
我想也想知道

热点排行