Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.
SPWeb web = SPContext.Current.Web;

                SPList customerList = web.Lists.TryGetList("MyList");
                if (customerList != null)
                {
                    SPQuery query = new SPQuery();
                    query.Query =
                        string.Format(
                            "<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 –  Martin 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 –  Martin 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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.