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

retrieve list items from the textbox text value and display the dropdownlist item for that particular list item

$
0
0

hi,

 I have created a custom list in my sharepoint :

List1 name:   employeedepartment -

               Title       empdepartment

               A             D1

               B             D2

               C             D3 

---------------------------------------------------------

List2  name:  employeedetails  

 emptitle            empname       empdepartment(lookup) --> from the list "employeedepartment"

   x                     Ram                 D1

   y                     Robert             D2

   z                     Rahim              D3

---------------------------------------------------------------

My task is to create a custom webpart that will be for searching this employee details by entering emptitle

For this, i have created a visual webpart using visual studio 2010, my webpart will be like this:

emptitle  --->  TextBox1                        Button1--> Text property : Search

empname---> TextBox2

empdepartment-->  DropDownList1

------------------------------------------------------------------------

For this, i wrote the code as follows:

                                                                                       

protected void Button1_Click(object sender, EventArgs e)
        {

            using (SPSite mysite = new SPSite(SPContext.Current.Site.Url))
         

  {
                using (SPWeb myweb = mysite.OpenWeb())
                {
                    SPList mylist = myweb.Lists["employeedetails"];
                    SPQuery query = new SPQuery();
                    query.Query = "<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>" + TextBox1.Text.ToString() + "</Value></Eq></Where>";
                    SPListItemCollection myitems = mylist.GetItems(query);
                    if (myitems.Count > 0)
                    {
                        foreach (SPListItem item in myitems)
                        {
                            string a1 = Convert.ToString(item["empname"]);
                            string a2 = Convert.ToString(item["empdepartment"]);

                            TextBox2.Text = a1;           // displaying   properly                                       
                            //DropDownList3.SelectedIndex = 1;                           

-------------------------------------------------------------------------------------------------------------------
 It is showing the list item in textbox according to the item entered in the textbox1... But I am stuck to show in the dropdown list. 

Suppose, if i enter X in textbox and click on search, then dropdownlist need to show D1,

                           for Y --> D2 and for Z-> D3... like that.

What code do i need to write in the button_click to show this... 

Please don't give any links...i just want code in continuation to my code.



Viewing all articles
Browse latest Browse all 11571

Trending Articles



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