在datalist的EditItemTemplate中,是修改数据状态,
有下面的请求:<asp:CheckBoxList ID="loveCheckBoxList" runat="server"  AutoPostBack="false" RepeatLayout="flow" RepeatDirection="Horizontal" SelectedValue='<%# com.fash.util.StringUtil.getCheckIndex()%>' DataSource='<%# com.fash.util.StringUtil.getLove()%>' DataTextField="value" DataValueField="key"></asp:CheckBoxList>
说明:返回的是一个hashtable问题:SelectedValue怎么返回2个以上checked的状态因为是多选,所以,存在这个问题如果不在页面里做逻辑运算,那么怎么处理比较好因为我在.cs里面通过
CheckBoxList cl = ((CheckBoxList)e.Item.FindControl("loveCheckBoxList"));
然后在进行数据绑定,但是cl怎么返回是null

解决方案 »

  1.   

    if(e.Item.ItemType == ListItemType.Edit)
    {
       CheckBoxList cl = ((CheckBoxList)e.Item.FindControl("loveCheckBoxList"));}
      

  2.   

    if(e.Item.ItemType == ListItemType.Edit)
    {}
      

  3.   

    if(e.Item.ItemType == ListItemType.Edit)
    {
       CheckBoxList cl = ((CheckBoxList)e.Item.FindControl("loveCheckBoxList"));}//这是一种也可以用
    CheckBoxList cl = ((CheckBoxList)e.Item.Cells[0].FindControl("loveCheckBoxList"));
      

  4.   

    都好象不行哦我贴出全部的代码<ASP:DataList id="DataList"  
                  RepeatColumns="1" 
                  runat="server"
                  BorderColor="black"
                  CellPadding="5"            
                  Font-Names="Verdana"
                  Font-Size="8pt"
                  OnItemCommand="DateList_ItemCommand"
                  DataKeyField="id">
    <asp:LinkButton ID="edit" runat="server" Text="修改" CommandName="edit"></asp:LinkButton>
    其他的省略。。
    <EditItemTemplate>
    。。
    <asp:CheckBoxList ID="loveCheckBoxList" runat="server"  AutoPostBack="false" RepeatLayout="flow" RepeatDirection="Horizontal"></asp:CheckBoxList>
    [显示一个多选的选择框]
    </EditItemTemplate>
     </asp:DataList>
    对应的cs文件 public void DateList_ItemCommand(object sender,DataListCommandEventArgs e){
       LinkButton lb = (LinkButton)e.CommandSource;
        if ("修改".Equals(lb.Text))
            {
                this.DataList.EditItemIndex = e.Item.ItemIndex;
                this.DataList.SelectedIndex = -1;
                if (e.Item.ItemType == ListItemType.EditItem){//好象不等
                    CheckBoxList cl = ((CheckBoxList)e.Item.FindControl("loveCheckBoxList"));
                    cl.DataSource= com.fash.util.StringUtil.getLove(); 
                    cl.DataTextField="value";
                    cl.DataValueField = "key";                
                }
                display();
                
            }}Lcindep110(Going Home) 的
    CheckBoxList cl = ((CheckBoxList)e.Item.Cells[0].FindControl("loveCheckBoxList"));
    根本不行,。这个好象是在datagrid里的吧
      

  5.   

    public void DateList_ItemCommand(object sender,DataListCommandEventArgs e){
       LinkButton lb = (LinkButton)e.CommandSource;
        if ("修改".Equals(lb.Text))
            {
                this.DataList.EditItemIndex = e.Item.ItemIndex;
                this.DataList.SelectedIndex = -1;
                CheckBoxList cl = (CheckBoxList)e.Item.Cells[0].FindControls("loveCheckBoxList"); //改为这样
                cl.DataSource= com.fash.util.StringUtil.getLove(); 
                cl.DataTextField="value";
                cl.DataValueField = "key"; 
                display();
                
            }}
      

  6.   

    CheckBoxList cl = (CheckBoxList)e.Item.Cells[0].FindControls("loveCheckBoxList"); //改为这err:Compilation Error 
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0117: 'System.Web.UI.WebControls.DataListItem' does not contain a definition for 'Cells'Source Error: Line 71:             if (objItemType == ListItemType.Item || objItemType == ListItemType.AlternatingItem)
    Line 72:             {
    Line 73:                 CheckBoxList cl = (CheckBoxList)e.Item.Cells[0].FindControls("loveCheckBoxList"); 
    Line 74:                     //.FindControl("loveCheckBoxList"));
    Line 75:                 cl.DataSource = com.fash.util.StringUtil.getLove();
     
      

  7.   

    if(dl.ItemType==ListItemType.Item||dl.ItemType==ListItemType.AlternatingItem)