Jasim Iqbal
3/7/2002 7:38:00 AM
hi michael,
thanx again for ur concern and reply. the code u have sned
is for WebForms not for MobileWebforms ....
so when i try the code it gives me error as ListControl in
WebForms is diffrent from that of SelectionListControl in
MobileWebForms.
when i apply the code (after changing the connection and
other changes for) u have send me i get error stating
somethin about Web Controls and Mobile controls.
the code u send is as follows (after that i have pasted my
MobileWebForm.aspx.cs code).
========== WebPage1.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace DropdownList
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.ListBox slst1;
private void Page_Load(object sender,
System.EventArgs e)
{
// Put user code to initialize the page here
SqlConnection cnn = new SqlConnection("server(local);database=pubs;user
id=sa;pwdÞvsa");
cnn.Open();
string sql = "Select job_id, emp_id from
employee order by emp_id";
response.write(sql+"<br>");
SqlCommand cmd = new SqlCommand(sql, cnn);
SqlDataReader myReader = cmd.ExecuteReader();
while (myReader.Read())
{
string dt;
string myValue = "";
string myText = "";
ListItem myItem;
for (int i=0;i<myreader.fieldcount; i++)
{
dt = myReader.GetDataTypeName(i);
if((dt == "decimal")||(dt
== "smallint"))
{
myValue = myReader.GetInt16
(i).ToString();
}
if((dt == "varchar")||(dt == "char"))
{
myText = myReader.GetString(i);
myItem = new ListItem(myText,
myValue);
slst1.Items.Add(myItem);
}
}//end for
}//end while
myReader.Close();
cnn.Close();
}
///////////////////////////////////////////////////
the code i have is for MobileWebForm.aspx.cs
************************MobileWebForm.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Mobile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.IO;
using System.Data.SqlClient;
private void slst1_Load(object sender, System.EventArgs e)
{
#region Selection List for Station
1
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;
string val="";
dt =
myReader.GetDataTypeName(i);
if(dt == "decimal")
{
slst1.DataValueField = (myReader.GetDecimal
(i)).ToString();
val =
(myReader.GetDecimal(i)).ToString();
}
if(dt == "varchar")
{
slst1.DataValueField = val;
slst1.DataTextField = myReader.GetString(i);
slst1.Items.Add (myReader.GetString(i));
}
}//end for
}//end while
// always call Close when done
reading.
myReader.Close();
// Close the connection when done
with it.
newmyConnection.Close();
#endregion
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required
by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support -
do not modify
/// the contents of this method with the
code editor.
/// </summary>
private void InitializeComponent()
{
this.cmdSchedule.Click += new
System.EventHandler(this.cmdSchedule_Click);
this.cmdBack.Click += new
System.EventHandler(this.cmdBack_Click);
this.Form2.Activate += new
System.EventHandler(this.Form2_Activate);
this.lst1.Load += new
System.EventHandler(this.lst1_Load);
this.cmdBooking.Click += new
System.EventHandler(this.cmdBooking_Click);
this.Form3.Activate += new
System.EventHandler(this.Form3_Activate);
this.cmdResv.Click += new
System.EventHandler(this.cmdResv_Click);
this.slst1.Load += new
System.EventHandler(this.slst1_Load);
this.slst2.Load += new
System.EventHandler(this.slst2_Load);
this.cmdSch.Click += new
System.EventHandler(this.cmdSch_Click);
this.Load += new
System.EventHandler(this.Page_Load);
}
#endregion