How to eliminate duplicate records in SPQuery (achieve linkage)

Source: Internet
Author: User

List:

Achieve linkage between categories and sub-categories

 

Private void BindIncidentCategory ()
{
Using (SPSite site = new SPSite (rootsiteurl ))
{
Using (SPWeb web = site. OpenWeb ())
{
SPList list = web. Lists ["IncidentCategory"];
SPListItemCollection listitem = list. Items;
DataTable dt = listitem. GetDataTable ();

DataView dvSort = new DataView (dt );
String [] colName = new string [] {"CategoryName "};
DataTable dtLargeSort = dvSort. ToTable (true, colName );

DropDownListIncidentCategory. DataValueField = "CategoryName ";
DropDownListIncidentCategory. DataValueField = "CategoryName ";
DropDownListIncidentCategory. DataSource = dtLargeSort;
DropDownListIncidentCategory. DataBind ();

BindIncidentSubCategory (DropDownListIncidentCategory. SelectedItem. Text );

}
}

}


Private void BindIncidentSubCategory (string IncidentCategory)
{
Using (SPSite site = new SPSite (rootsiteurl ))
{
Using (SPWeb web = site. OpenWeb ())
{
SPList list = web. Lists ["IncidentCategory"];
SPQuery query = new SPQuery ();
Query. query = "<Where> <Eq> <FieldRef Name = 'categoryname'/> <Value Type = 'text'>" + IncidentCategory + "</Value> </Eq> </Where> ";
SPListItemCollection listitem = list. GetItems (query );
DataTable dt = listitem. GetDataTable ();
DropDownListIncidentSubCategory. DataTextField = "SubCategoryName ";
DropDownListIncidentSubCategory. DataValueField = "SubCategoryName ";
DropDownListIncidentSubCategory. DataSource = dt;
DropDownListIncidentSubCategory. DataBind ();
}
}
}

 

Protected void DropDownListIncidentCategory_SelectedIndexChanged (object sender, EventArgs e)
{
BindIncidentSubCategory (DropDownListIncidentCategory. SelectedItem. Text. Trim ());

}

 

 

Set the AutoPostBack attribute in DropDownListIncidentCategory to true.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.