Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11508

CAML Query in SP2010

$
0
0

I want to create a webpart that contains two list boxes:

First List box will display all the fields of a particular List in a particular SharePoint site.

When the User selects any of the Fields in the List box, an event get fired that lists all the items under that Field only in the second ListBox. Please look at the asterisks below. Can I write a dynamic CAML Query for it, replacing a variable in place of Fieldref Name = ? 

namespace SharePointProject1.VisualWebPart1

{

 public partial class VisualWebPart1UserControl : UserControl

{

 protected void Page_Load(object sender, EventArgs e)

{

 using (SPSite siteC = new SPSite("fskdjfaskdf"))

{

 using (SPWeb site = siteC.OpenWeb())

{

 SPList list = site.Lists["Test List"];

 for (int i = 0; i < list.Fields.Count; i++)

{

 string F = list.Fields[i].ToString();

ListBox1.Items.Add(F);

}}}}

 protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)

{

 if (ListBox1.SelectedIndex> -1)

{

 using (SPSite siteC = new SPSite("faskjdfhasjdfhsadf"))

{

 using (SPWeb site = siteC.OpenWeb())

{

 SPList list = site.Lists["Test List"];

 string F = ListBox1.SelectedItem.Text;

 SPQuery query = new SPQuery();

query.Query = "<Where><Eq><FieldRef Name= 'F'/><Value Type</Eq></Where>";

/****************************** I want to use Field name stored in F as the Fieldref Name******/

 SPListItemCollection G = list.GetItems(query);

 for (int L = 0; L < G.Count; L++ )

{

 SPListItem K = G[L];

 string H = K.ToString();

ListBox2.Items.Add(H);

}}}}}}}


Viewing all articles
Browse latest Browse all 11508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>