我在GridView页尾添加了几个Label,代码如下,可以我想在后台计算一个值后赋给他们,不知该如何做<asp:GridView ID="grid_RoomNumber" runat="server" Width="100%" 
        AllowPaging="True" CellPadding="4" PageSize="15" 
            AllowSorting="True" BackColor="White" 
                BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" 
                EmptyDataText="没有查询到数据,重新选择查询条件" 
               onpageindexchanging="grid_RoomNumber_PageIndexChanging" 
               onsorting="grid_RoomNumber_Sorting" DataKeyNames="房号" >
                <PagerSettings Position="TopAndBottom" Mode="NextPreviousFirstLast" 
                    PreviousPageImageUrl="~/images/previous.jpg" />
                <FooterStyle BackColor="#001F60" ForeColor="#D9E6FF" />
                <RowStyle BackColor="White" ForeColor="#003399" />
                         <PagerTemplate>
         
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 总床位
            <asp:Label ID="lab_zcw" runat="server" Text="0"></asp:Label>个
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 已使用
            <asp:Label ID="lab_ysy" runat="server" Text="0"></asp:Label>个
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 可使用
            <asp:Label ID="lab_ksy" runat="server" Text="0"></asp:Label>个
                             </PagerTemplate> 
                             
                <Columns>
 
                       <asp:TemplateField>
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox1" runat="server"  />
                        </ItemTemplate>
                    </asp:TemplateField>
                    
                    <asp:TemplateField HeaderText="序号" >
                        <ItemTemplate>
                            <asp:Label ID="lblIndex" runat="server" Text='<%#Container.DataItemIndex+1 %>'></asp:Label>
                        </ItemTemplate >
                    </asp:TemplateField>
 
                </Columns>
                <PagerStyle BackColor="#D9E6FF" ForeColor="#003399" HorizontalAlign="Left" />
                <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                <HeaderStyle BackColor="#001F60" Font-Bold="True" ForeColor="#CCCCFF" />
                <AlternatingRowStyle BackColor="#D9E6FF" />
    
            </asp:GridView>

解决方案 »

  1.   

    在后台用lab_zcw.text="123"这样不行,报错的
    能否讲清楚些啊?或给个代码示例
      

  2.   

    Label label1=grid_RoomNumber.findcontrol("控件编号") as Label
    label1.text="";
      

  3.   

      //设置
        void SetLable()
        {        GridViewRow gvr = rid_RoomNumber.BottomPagerRow;
            if (gvr != null)
            {
                Lable lab_zcw = (Lable)gvr.FindControl("lab_zcw");
                Lable lab_ysy = (Lable)gvr.FindControl("lab_ysy");
                Lable lab_ksy = (Lable)gvr.FindControl("lab_ksy");
                  //To do something
                lab_zcw.Text="123";
                lab_ysy.Teext="123";
                lab_ksy.Text="123";
            }
        }
    将这个函数到Page_Load()中 或则Button 事件中(放在事件中要先绑定到GridView,然后在调用该方法,因为运行代码是有顺序的。)
       protected void Page_Load(object sender, EventArgs e)
        {
            //
           SetLable();
        }
      

  4.   

    Label txtLiaisons = grdLinkMan.FindControl("txtLiaisons") as Label ;
      

  5.   

    grid_RoomNumber 中找你要的Label控件就行
      

  6.   

    本帖最后由 net_lover 于 2011-05-06 16:02:26 编辑