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


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure