SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
SPWeb web = SPContext.Current.Web;

                SPList customerList = web.Lists.TryGetList("MyList");
                if (customerList != null)
                    SPQuery query = new SPQuery();
                    query.Query =
                            "<Where><BeginsWith><FieldRef Name='ProductNumber' /><Value Type='Text'>{0}</Value></BeginsWith></Where>");

                    query.RowLimit = 10;

                    SPListItemCollection items = customerList.GetItems(query);

                    foreach (SPListItem customer in items)

                        TextBox_Name.Text = customer["Title"].ToString();
                        TextBox_ProdNum.Text = customer["ProductNumber"].ToString();
                        TextBox_Color.Text = customer["Color"].ToString();
                        TextBox_ListPrice.Text = customer["ListPrice"].ToString();
                        TextBox_MoreInfo.Text = customer["More Info"] != null
                                                    ? customer["More Info"].ToString()
                                                    : string.Empty;
share|improve this question
Accept answers for previous questions if they helped! – Arsalan Adam Khatri Dec 3 '12 at 9:02
they didnt help – Batistuta Dec 3 '12 at 9:06
Can you explain why exactly you want to achive? so far your querying a list and populating some controls with the list values. – ali Sharepoint Dec 3 '12 at 9:13
hi! i want to update column in an list true textboxes , my problem is that , all the items that i have in my list get updated – Batistuta Dec 3 '12 at 9:28
First of all, that code should not compile (since the string.Format needs at least two parameters). Second, that query might return a collection of SPListItems which if you iterate to update will obviously update ALL the elements in the SPListItemCollection – Jaime Dec 3 '12 at 13:49

Maybe I am just stupid but you aren't formatting any variable into the CAML statement at all.

// Add the variable to the string.Format
query.Query = string.Format("<Where><BeginsWith><FieldRef Name='ProductNumber' /><Value Type='Text'>{0}</Value></BeginsWith></Where>", myVariable);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.