本文介绍了复选框将在数据列表中的特定条件下被选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在显示带有复选框的数据列表.使用此代码处理所有子类别..

 <   asp:DataList     ID   ="  subcategorydatalist"   ="span>    runat   =" 服务器"    RepeatColumns   ="   3"    RepeatDirection   =" 垂直"  >> 
    <   ItemTemplate  > 
        <   asp:CheckBox     ID   ="  chksubcategory"     runat   ="  服务器"   文本  ='  <%#Eval("  SubCategory" )%> '   / > 
    <  /ItemTemplate  > 
<  /asp:DataList  >  



我的要求是从子类别表中显示子类别. ypinformation1表中存在的子类别应选中,其他子类别将不选中.

aspx.cs:-
-----------

 受保护的 无效 Page_Load(对象发​​件人,EventArgs e)
    {
        如果(会话["  UserID" ] != &&会话["  UserID" ]!= " " )
        {
            UPOBJ.U_UserID = Convert.ToString(会话["  UserID" ]);;
            UPOBJ.U_UserType = Convert.ToInt32(会话["  UserType" ]));
            会话["  ID" ] = UPOBJ.U_UserID;
        }
        其他
        {
            Response.Redirect(" 〜/Login.aspx?ReturnUrl ="  + Request.Url.PathAndQuery.Replace (" &" "  ^"));
        }

        如果(Request.QueryString ["  YPID" ]!= && Request.QueryString ["  YPID" ]!= " " )
        {
            LPOBJ.L_YPID = Convert.ToInt32(Request.QueryString ["  YPID" ]);
        }
        其他
        {
            AlertMessage(" 请选择要编辑的记录" );
            Response.Redirect("  EditListing.aspx" );
        }
        如果(!IsPostBack)
        {
            dr = ABLOBJ.GetYPInformationListingByID(LPOBJ);
            如果(dr.HasRows)
            {
                 while (dr.Read())
                {
                    txtYPID.Text = dr ["  YPID" ].ToString();
                    txtCategory.Text = dr [" 类别" ]!= ? Convert.ToString(dr [" 类别" ]): " " ;
                    txtSubCategory.Text = dr ["  SubCategory" ]!= ? Convert.ToString(dr ["  SubCategory" ]): " " ;
                    txtCompanyName.Text = dr ["  CompanyName" ]!= ? Convert.ToString(dr ["  CompanyName" ]): " " ;
                    UPOBJ.U_Category = txtCategory.Text.ToString();
                }
            }
            ds = ABLOBJ.GetRelatedSubCategories(UPOBJ);
            ds1 = ABLOBJ.GetSelectedSubCategories(LPOBJ);


            subcategorydatalist.DataSource = ds;
            subcategorydatalist.DataBind();

        }

    } 



所有正在显示的子类别都由数据集ds显示..但我对ds1中存在哪些子类别的子类别已被检查剩余的要求未选中. div>




Hi I am displaying datalist with checkboxes. Dispalying all subcategories using this code..

<asp:DataList ID="subcategorydatalist" runat="server" RepeatColumns="3" RepeatDirection="Vertical">
    <ItemTemplate>
        <asp:CheckBox ID="chksubcategory" runat="server" Text='<%# Eval("SubCategory") %>' />
    </ItemTemplate>
</asp:DataList>



My requirement is that the subcategories are displayed from subcategories table. Subcategories which are present in ypinformation1 table should be checked and other will be unchecked.

aspx.cs:--
-----------

protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserID"] != null && Session["UserID"] != "")
        {
            UPOBJ.U_UserID = Convert.ToString(Session["UserID"]);
            UPOBJ.U_UserType = Convert.ToInt32(Session["UserType"]);
            Session["ID"] = UPOBJ.U_UserID;
        }
        else
        {
            Response.Redirect("~/Login.aspx?ReturnUrl=" + Request.Url.PathAndQuery.Replace("&", "^"));
        }

        if (Request.QueryString["YPID"] != null && Request.QueryString["YPID"] != "")
        {
            LPOBJ.L_YPID = Convert.ToInt32(Request.QueryString["YPID"]);
        }
        else
        {
            AlertMessage("Please Select the Record For Editing");
            Response.Redirect("EditListing.aspx");
        }
        if (!IsPostBack)
        {
            dr = ABLOBJ.GetYPInformationListingByID(LPOBJ);
            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    txtYPID.Text = dr["YPID"].ToString();
                    txtCategory.Text = dr["Category"] != null ? Convert.ToString(dr["Category"]) : "";
                    txtSubCategory.Text = dr["SubCategory"] != null ? Convert.ToString(dr["SubCategory"]) : "";
                    txtCompanyName.Text = dr["CompanyName"] != null ? Convert.ToString(dr["CompanyName"]) : "";
                    UPOBJ.U_Category = txtCategory.Text.ToString();
                }
            }
            ds = ABLOBJ.GetRelatedSubCategories(UPOBJ);
            ds1 = ABLOBJ.GetSelectedSubCategories(LPOBJ);


            subcategorydatalist.DataSource = ds;
            subcategorydatalist.DataBind();

        }

    }



all subcategories are displaying are displaying by the dataset ds..but my requirement which subcategories are present in ds1 that subcategories are checked remaining are unchecked..there is any chance for comparing the datasets

解决方案




这篇关于复选框将在数据列表中的特定条件下被选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 08:05