J
JB
Hello
In my ASP.NET application I have Web Control containing a DropDownList
which I populate
from a datset in the Web Controls codebehind page. I then put the Web
Controls on the default.aspx .
From the default.aspx I access the Web Control's id tag to access the
DropDownList in the Web
Control. The FindControl method apparently finds the DropDownList in the
Web Control but an error display when I try to display the value of the first
item in the DropDownList residing in the Web Control.
How do I access the first item in the DropDownList in the Web Control, the
code is below;
Here is the Web Control:
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="CallInformation.ascx.cs" Inherits="CallInformation" %>
<asp:Label ID="Label5" runat="server" Text="Call Information"
style="font-weight: 700"></asp:Label><br />
<asp:Label ID="Label1" runat="server" Text="Call Type:"></asp:Label>
<aspropDownList ID="lstCallType" runat="server" Height="16px" Width="200px">
</aspropDownList>
-------------------------------------
Here is where I populate the Web Control:
public partial class CallInformation : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet rtcar = new DataSet();
DataSet dscar = new DataSet();
cardata allcars = new cardata();
dscar = allcars.getcar(rtcar);
lstCallType.DataSource = dscar.Tables[0];
lstCallType.DataTextField =
dscar.Tables[0].Columns["CarID"].ColumnName.ToString();
lstCallType.DataTextField =
dscar.Tables[0].Columns["Make"].ColumnName.ToString();
lstCallType.DataTextField =
dscar.Tables[0].Columns["Color"].ColumnName.ToString();
lstCallType.DataTextField =
dscar.Tables[0].Columns["PetName"].ColumnName.ToString();
lstCallType.DataBind();
lstCallType.SelectedIndex = 0;
}
}
-----------------------------------------
Here is the default.aspx attempts to display the
first items value in the DropDownList in the Web Control:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DropDownList b;
b = (DropDownList)CallInformation1.FindControl("lstCallType");
if (b != null)
{
MessageBox.Show("lstCallType was found" +
CallInformation1.Visible.ToString());
}
else
MessageBox.Show("lstCallType not found");
string carname = b.Items[1].Value;
MessageBox.Show("this is the value in the DropDownList" +
carname.ToString());
}
}
In my ASP.NET application I have Web Control containing a DropDownList
which I populate
from a datset in the Web Controls codebehind page. I then put the Web
Controls on the default.aspx .
From the default.aspx I access the Web Control's id tag to access the
DropDownList in the Web
Control. The FindControl method apparently finds the DropDownList in the
Web Control but an error display when I try to display the value of the first
item in the DropDownList residing in the Web Control.
How do I access the first item in the DropDownList in the Web Control, the
code is below;
Here is the Web Control:
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="CallInformation.ascx.cs" Inherits="CallInformation" %>
<asp:Label ID="Label5" runat="server" Text="Call Information"
style="font-weight: 700"></asp:Label><br />
<asp:Label ID="Label1" runat="server" Text="Call Type:"></asp:Label>
<aspropDownList ID="lstCallType" runat="server" Height="16px" Width="200px">
</aspropDownList>
-------------------------------------
Here is where I populate the Web Control:
public partial class CallInformation : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet rtcar = new DataSet();
DataSet dscar = new DataSet();
cardata allcars = new cardata();
dscar = allcars.getcar(rtcar);
lstCallType.DataSource = dscar.Tables[0];
lstCallType.DataTextField =
dscar.Tables[0].Columns["CarID"].ColumnName.ToString();
lstCallType.DataTextField =
dscar.Tables[0].Columns["Make"].ColumnName.ToString();
lstCallType.DataTextField =
dscar.Tables[0].Columns["Color"].ColumnName.ToString();
lstCallType.DataTextField =
dscar.Tables[0].Columns["PetName"].ColumnName.ToString();
lstCallType.DataBind();
lstCallType.SelectedIndex = 0;
}
}
-----------------------------------------
Here is the default.aspx attempts to display the
first items value in the DropDownList in the Web Control:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DropDownList b;
b = (DropDownList)CallInformation1.FindControl("lstCallType");
if (b != null)
{
MessageBox.Show("lstCallType was found" +
CallInformation1.Visible.ToString());
}
else
MessageBox.Show("lstCallType not found");
string carname = b.Items[1].Value;
MessageBox.Show("this is the value in the DropDownList" +
carname.ToString());
}
}