|
| Re: Populate in dropdown list control |
 |
Fri, 14 Mar 2008 16:37:02 +000 |
using System.Collections.Generic;
public ListItem[] LoadItems()
{
List<ListItem> list=new List<ListItem>();
OracleConnection Conn = new OracleConnection();
Conn.ConnectionString = ConfigurationSection.DbConnectionString;
OracleCommand cmd = new OracleCommand("SELECT ID, NAME FROM CNT_CLIENTS
WHERE ID IN (SELECT CLT_ID FROM CNT_CLIENT_USER_ROLES WHERE CLU_ID = '"+
SessUserID +"')ORDER BY NAME", Conn);
Conn.Open();
OracleDataReader dr= cmd.ExecuteReader();
ddlClient.Items.Clear();
while(dr.Read())
{
list.Add(new ListItem(dr[1].ToString(),dr[0].ToString());
}
Conn.close();
return list.ToArray();
}
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
ddlClient.Items.AddRange(LoadItems());
}
}
|
| Post Reply
|
| Re: Populate in dropdown list control |
 |
Fri, 14 Mar 2008 16:55:41 +000 |
Works perfectly great. Thanks i'll have a good weekend now.
|
| Post Reply
|
| Populate in dropdown list control |
 |
Fri, 14 Mar 2008 18:29:54 +000 |
Hello need some help on this one. I am using ASP.NET with C# and Oracle
database. I am trying to return some values from my select statement to fill my
dropdown list control. I am designing this in a 3 tier architecture. Here is my
codes. I am getting an error which states "Object reference not set to an
instance of an object." I am returning the field name "NAME" to
be filled in my dropdown control. What I am doing wrong?
List.cs file codepublicstaticstring _GetClientList()
{string clients = string.Empty;int SessUserID =
Convert.ToInt32(HttpContext.Current.Session["UserID"]);
OracleConnection Conn = newOracleConnection();Conn.ConnectionString =
ConfigurationSection.DbConnectionString;
OracleCommand cmd = newOracleCommand("SELECT ID, NAME FROM CNT_CLIENTS
WHERE ID IN (SELECT CLT_ID FROM CNT_CLIENT_USER_ROLES WHERE CLU_ID = '"+
SessUserID +"')ORDER BY NAME", Conn);OracleDataAdapter adapter =
newOracleDataAdapter(cmd);
DataSet ds = newDataSet();cmd.CommandType = CommandType.Text;
Conn.Open();
adapter.Fill(ds);DataTable table = ds.Tables["CNT_CLIENTS"];clients =
ds.Tables["CNT_CLIENTS"].ToString(); Error here "Object
reference not set to an instance of an object."
Conn.Close();return clients;
}
Display.aspx (behind page)protectedvoid Page_Load(object sender, EventArgs e)
{if (!IsPostBack)
{ddlClient.DataSource = UserAccess._GetClientList();
ddlClient.DataBind();
}
}
|
| Post Reply
|
| Re: Populate in dropdown list control |
 |
Fri, 14 Mar 2008 18:58:34 +000 |
Try:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
OracleConnection Conn = new OracleConnection();
Conn.ConnectionString = ConfigurationSection.DbConnectionString;
OracleCommand cmd = new OracleCommand("SELECT ID, NAME FROM CNT_CLIENTS
WHERE ID IN (SELECT CLT_ID FROM CNT_CLIENT_USER_ROLES WHERE CLU_ID = '"+
SessUserID +"')ORDER BY NAME", Conn);
Conn.Open();
OracleDataReader dr= cmd.ExecuteReader();
ddlClient.Items.Clear();
while(dr.Read())
{
ddlClient.Items.Add(new ListItem(dr[1].ToString(),dr[0].ToString());
}
Conn.close();
}
}
|
| Post Reply
|
| Re: Populate in dropdown list control |
 |
Fri, 14 Mar 2008 19:12:29 +000 |
Your solution looks like a solution however I prefer not to have my query string
on the presentation layer. I have my query strings and connection inside a
Class file (List.cs). How can i do that
|
| Post Reply
|
|
|
|
|
|
|
|
|
|