Home » C# Programming

drop down list

hi all...
i have done a simple drop down list...and it's working good...
i take "name' from table student...

separately i write coding for split string into multiple...here's my problem.Now i want to add that split into drop down list to split data into drop down list...

please let me know how to add that method into drop down list..Here's the codes i wrote..



//Connection to database and column to split***********************************
protected void Page_Load(object sender, EventArgs e)

String strConnection = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\jeeva\\My Documents\\Visual Studio 2008\\WebSites\\WebSite2\\App_Data\\tempdb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";

String strQueryString = "select * from student";

using (SqlConnection sqlConnection = new SqlConnection(strConnection))
SqlCommand sqlCommand = new SqlCommand(strQueryString, sqlConnection);

SqlDataReader reader = sqlCommand.ExecuteReader();

while (reader.Read())



//method for split data*********************************
private void splitData (String strData,ref ArrayLit alData)
String strTemp = null;
int nCount = 0;

alData = new ArrayList();

foreach (char ch in strData)
if (ch != ' ')
strTemp = strTemp + ch;

else if (ch == ' ')
if (!String.IsNullOrEmpty(strTemp))
strTemp = null;
if (strTemp != null)




2 Answers Found


Answer 1

Welcome to the MSDN Forums.

Actually, .NET Framework already has the needed code for spliting. Let's see how:

foreach(object o in dropDownList.Items)
 string[] splitted = o.ToString().Split(newchar[]{' '});//split by ' '(space)foreach(string s in splitted)
 dropDownList2.Items.Add(s);//add them to another drop  down

Hope this helps.




Answer 2

if i do the connection using sql data  source...where i can add  this coding...

i try to add this codes  into page load area and it's nt working..

please guide me..




<form id="form1" runat="server">
        <asp:DropDownList ID="dropDownList" runat="server"
            DataSourceID="SqlDataSource1" DataTextField="Value" DataValueField="Value"
        <br />
        <br />
        <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True"
            AutoPostBack="True" Height="34px"
            onselectedindexchanged="DropDownList1_SelectedIndexChanged" Width="111px">
        <br />
        <br />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:AED_Panasonic_DataConnectionString %>"
        SelectCommand="SELECT [Value] FROM [UDFList]"></asp:SqlDataSource>


Search for  drop down list


Hi all,

I have a requirement to populate a drop down based upon the value selected in the previous drop down's value in MOSS 2007.EX: for Example I have a documnet library and I am populating the value for a column in the DOcument library based upon the value from other list in the same site.The Document library has a column COuntry and CIty.There is another list with name regions and lists all countries with cities as items .The city column in the Document library has to be populated based upon the selected value from the COuntry value automatically.After Selecting the country column in DOcument library as look up for COuntry from the list,the cities for that country should also be retrieved automatically in the choice column of city.Is this possible in OOTB(No SPD or Visual Studio is provided) in SharePoint.Look up collumn has some restrictions i guess.please help me.



First off I'm very new to Ajax for .NET.  I have a Cascading drop down list that is working fine to load the correct lists however I would like to have the last one initiate a query and display a datagrid on the same page containing the results of the query.  Without Ajax involved this seems rather easy by using autopostback on the drop downs.  If I could do it through Ajax that would be great but I can settle with having the page to reload to display the data.  Right now I'm not sure how to do either.  I enabled autopostback on the last drop down and wrote a method for it but I get an error at runtime saying:

Invalid postback or callback argument

So I'm really not sure what to do to get this to work right.

Any help would be appreciated.





Some one can help me, if possible screen shots.
Environment : MOSS 2007, InfoPath 2007

Hi All,

I have two drop downs in one row... when you  editing the row,  these dropdowns value gets populated...but I want to display values in 2nd drop base on selecttion of  1st drop down value...

When initially gridview populates, it displays all records in a label.control... as soon as u click on edit button.... for 1st and 2nd col... populate dropdown values...... so In EDIT mode..if you select drop value of 1st ddl then base on that value 2nd drop down should get populate.....

Please help ASAP....



I am using a data bound drop down list control in a .net 3.5 ASP.net web forms page.  The control databinds correctly and the selected index changed event fires correctly most of the time, but not all.

When the page first loads, the DDL shows all of the correct items and of course defaults to item(0).
I use the control to select a different item (other than item 0) and the event fires correctly. 
Now, that I'm on a different item, I try to go back to the first item in the list (Item(0)).  The page appears to update but actualy reverts to the static place holder data defined in the base .aspx markup rather than the live data from the database.  As a matter of fact, if VS2010 hits the my breakpoint in the index changed event at all, it's AFTER the browser shows the new page rather than before the page is refreshed.

.aspx markup for the control:
<asp:DropDownListID="ddlTransmitter"runat="server"DataSourceID="SqlDataSource2" DataTextField="TransmitterName"DataValueField="TransmitterTypeID" Width="250px"AutoPostBack="True">

Code Behind:
ProtectedSub ddlTransmitter_SelectedIndexChanged(ByVal sender AsObject, ByVal e As System.EventArgs) Handles ddlTransmitter.SelectedIndexChanged





Has anyone else come across this hit or miss event firing problem?

My Excel template has a number of fields that use validation drop down lists within a cell. How do I select one of these options using the SDK? Just setting the cell value doesn't work.


I would like to create a Drop-Down Form Field that when i choose any of the items on the list, it will generate a number in a deferent TextFormField.


I have a list of 2 cars Item1= Toyota then Item2= Honda then when i choose Item1, i want word to show me how much it cost in another TextFormField.

Is it possible?

Thank you very much.


In TFS, the items in any dropdown list are in alphabetical order (such as Triage filed). Is there a way to order it in other way? I understand you can always order it in your way if you put a number in front of the text, however it is not an elegant solution. Thanks.


Jason Luo



my main window contains 2 grids. in the first I check checkboxes that populate the second grid with rows. one of the rows cells is combobox from which I try to choose list item.

the place of the combobox list in the CUIT is strange : it is placed outside the main window and include only the first item in each list as list item. my test fails - it doesn't recognize the items.

moreover my try to choose item from the first row's combobox is recorded as

// Type 'Surname' in 'Surname' cell

uISurnameCell.Value =this.Choose_list_itemParams.UISurnameCellValue;

instead of

// Click 'Building Number' list item

Mouse.Click(uIBuildingNumberListItem, newPoint(70, 10));

I try to create my own code, the main problem is that the list doesn't know its childrens (the list is unique for each row)

is there a general problem working with grid's comboboxes ? is there a workaround ?

thanks, Ayelet




HI all, 

I have a Drop-Down list in my InfoPath form and I am loading some other fields based on the selection of the drop-down list. so that I have written code as follows for the "changed" event of the drop down list.

public void ProjectName_Changed(object sender, XmlEventArgs e)
            string projectId = e.NewValue;
            dataQueryConnection = (AdoQueryConnection)this.DataConnections["ProjectInformation"];
            dataQueryConnection.Command = dataQueryConnection.Command + string.Format(" WHERE ProjectId = '{0}'",             projectId);

For the first time when I change an item in the drop down list its working fine but for the subsequent changes of items(2nd time, etc..) its give the following error,

The query cannot be run for the following DataObject: ProjectInformation
InfoPath cannot run the specified query.
[0x80040E14][Microsoft OLE DB Provider for SQL Server] Incorrect syntax near the keyword 'WHERE'.

And this is the reason, for the second time,
dataQueryConnection.Command = select "EmployeeID","Accountname","ProjectName","ProjectId","ProjectRole","BillableUtilization","ClientName","BillingCode","BUHead" from "TRF"."hrt_vw_ProjectInformation" as "hrt_vw_ProjectInformation" WHERE ProjectId = '3072507' WHERE ProjectId = '3076478'

subsequent event firing biding the WHERE clause every time with the previous executed query. 

How I can over come from this issue?




Can you let me know how to enable drag and drop of files in Sharepoint List in Outlook 2007. I have installed MOSS 2007. Currently its in read only mode.




I have the following problem:

On my InfoPath form, I have a drop down list that contains cities, and based on the selection of the user, I would like to pre-fill some fields on the form, like telephone and fax number, address of the company, etc. I have written an event handler that is run each time the selection in the drop down list changes. But when I publish the form on the SharePoint server, this functioanlity seems to be lost. If I change the selected item in the drop down list, nothing happens; whilst in the InfoPath client everything runs as expected.

Why does this happen? Is the drop down list's Changed event unavailable in a browser-enabled form? Is it possible to catch this event at all?

Thanks for your reply,


I create a new public view for a list and it appears on thte views drop down list.  if I edit the view page and modify the webpart,  this view then dissapears from the list of views in the view drop down list.  The View page is still there and accessable via it URL, but I would still like on on the views drop down.

I have been scrolling through the forums to determine if it is possible to add a drop-down list to the top link bar in SPF2010. So far I have only found that this can be done in the server edition only. What do I need to do in SPF2010 to activate or create this feature, given SPF2010 does not have the Publish function.


Also, I would like to know if certain sites can be excluded from the list, but the drop-down list remain dynamic in including new subsites added.


Any help would be greatly appreciated!





I have two cascading drop down boxes cboElementGroup and cboElement. cboElementGroup has two columns and cboElement has three. Both display the correct values when a choice is made in cboElementGroup. My problem is that although I can read a text value in the combo's the value which gets stored in the underlying table is the index number. I am expecting the displayed value to be stored in the db field not the number. I can't figure out why. Can you offer a solution

cboElementGroup = 2 columns = ElementGroupID and ElementGroupName. One is visible.

cboElement = 3 columns = SubElementPKID and SubElementID and SubElement. One is visible.

The values for the cboElementGroup are from one table and cboElement are from another.

cboElement is queried with qrySubElements


I would like to filter a drop down list based on a seperate custom list which has 2 columns, StaffName and Department. I can see 2 approaches, one being a cascading solution which is not feasible at the moment as I am unable to modify the underlying structure or use a "Calculated (calculation based on other columns)" field where I apply the filter here. Not sure if/how this can be done, but something like;

IF([Staff],Department="Accounts" ~ then add formular to show only StaffName from "Accounts"



I have data for 3 months in a report. I created a Filter in Report Builder 1.0 that prompt me to select a date for which I want to view the Data. But When I'm selecting date from the drop down list, the date is in no order. If I have to see data for 3 consecutive days, I have to search for the date from the long list as the dates are in no order. So how can I sort the dates in the drop down list?




I want to add some user interaction into SSRS report . How to add interaction into my report.



how can I update my gridview using a dropdown list?


A customer requested the possibility of drag 'n dropping files into SharePoint as list attachments. The best solution would be to provide a drag & drop area in the new item form. Instead of adding the attachments the old fashioned way, the user could just drag and drop their files into this area and they would be added as normal attachments to the item.

I can code most of it, I'm just not sure what to do with the newly uploaded files. How does SharePoint store these in advance to storing the actual item itself? Are these API calls available?


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure