[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.mobile

Control 'SelectionList' Problem

Jasim Iqbal

3/5/2002 8:52:00 AM

thanx michael for ur reply, actually meanwhile i already
found the problem ...

but i do have another question ..

i have made a selection list of type 'ListBox' .. now i
have to add cities name to the list from a database and
have to assign each cities_id from data base to the value
like ....

(HTML Code when viewed in IE browser)
<select size="8" name="slst1">
<option value3>Chatham
<option value4>Guelph
<option value0>Kitchener
<option value0>London
</select>

but instead i get following code ...

<select size="8" name="slst1">
<option value="Chatham">Chatham
<option value="Guelph">Guelph
<option value="Kitchener">Kitchener
<option value="London">London
</select>

my code for the control is as following ...

CODE c-Sharp (in the code Station_ID should be 'value' and
Station_Name should appear in the control to see)
******************************************

private void slst1_Load(object sender, System.EventArgs e)
{
#region Show Code
SqlConnection newmyConnection =
new SqlConnection("user
id=sa;password=sa;server=challenge360;Trusted_Connection=no
;databaseºckTest");
string mySelectQuery = "SELECT
Station_ID, Station_Name FROM tblStation_Info";
SqlCommand myCommand = new
SqlCommand (mySelectQuery,newmyConnection);
newmyConnection.Open();
SqlDataReader myReader;
myReader = myCommand.ExecuteReader
();

while (myReader.Read())
{
for (int i=0;
i<myReader.FieldCount; i++)
{
string dt;
dt =
myReader.GetDataTypeName(i);
if(dt == "decimal")
{

slst1.DataValueField = (myReader.GetDecimal
(i)).ToString();
}
if(dt == "varchar")
{

slst1.DataTextField = myReader.GetString(i);

slst1.Items.Add (myReader.GetString(i));
}
}//end for
Console.WriteLine();
}//end while

// always call Close when done
reading.
myReader.Close();

Console.WriteLine("The Values are
Shown!");
// Close the connection when done
with it.
newmyConnection.Close();
#endregion
}