Click to See Complete Forum and Search --> : DropDownList problem


solomon_13000
02-03-2007, 11:23 PM
ModifyUserRegistration.aspx
---------------------------


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ModifyUserRegistration.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<br /><br />
<form id="form1" runat="server">
<asp:Repeater ID="rptItems" runat="server" OnItemCommand="rptItems_ItemCommand">
<HeaderTemplate>
<table border="0" width="304">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td width="294" colspan="2" bgcolor="#FFCC99">
<p align="center"><b>Modify User Registration</b></p>
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td style="width: 100px"><asp:Label ID="Label1" runat="server" Text="Email"></asp:Label></td>
<td style="width: 205px"><%# Eval("Email") %></td>
</tr>
<tr>
<td style="width: 100px"><asp:Label ID="Label2" runat="server" Text="Password"></asp:Label></td>
<td style="width: 205px"><%# Eval("Password") %></td>
</tr>
<tr>
<td style="width: 100px"><asp:Label ID="Label3" runat="server" Text="FirstName"></asp:Label></td>
<td style="width: 205px"><%# Eval("FirstName") %></td>
</tr>
<tr>
<td style="width: 100px"><asp:Label ID="Label4" runat="server" Text="LastName"></asp:Label></td>
<td style="width: 205px"><%# Eval("LastName") %></td>
</tr>
<tr>
<td style="width: 100px"><asp:Label ID="Label5" runat="server" Text="Country"></asp:Label></td>
<td style="width: 205px"><%# Eval("Country") %></td>
</tr>
<tr>
<td style="width: 100px"><asp:Label ID="Label6" runat="server" Text="PostalCode"></asp:Label></td>
<td style="width: 205px"><%# Eval("PostalCode") %></td>
</tr>
<tr>
<td style="width: 100px"><asp:Label ID="Label7" runat="server" Text="Gender"></asp:Label></td>
<td style="width: 205px"><%# Eval("Gender") %></td>
</tr>
<tr>
<td style="width: 100px"><asp:Label ID="Label8" runat="server" Text="DOB"></asp:Label></td>
<td style="width: 205px"><%# Eval("DOB") %></td>
</tr>
<tr>
<td style="width: 100px"><asp:Label ID="Label9" runat="server" Text="Status"></asp:Label></td>
<td style="width: 205px"><asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList></td>
</tr>
<tr>
<td style="width: 100px"></td>
<td style="width: 205px">
</td>
</tr>
<tr>
<td style="width: 100px"></td>
<td style="width: 205px">
<asp:Button ID="Button1" runat="server" Text="Modify" OnClick="Button1_Click" />
</td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 205px; text-align: right;">
&nbsp;</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</form>
</body>

</html>






ModifyUserRegistration.aspx.cs
------------------------------


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String[] status = { "Enabled", "Disabled" };
DropDownList1.DataSource = status;
DropDownList1.DataBind();


if (!Page.IsPostBack)
LoadData();
}

private void LoadData()
{
String videoID = Request.QueryString["VideoID"];
SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString);
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = cnn;
myCommand.CommandText = "SELECT * FROM Authentication WHERE AuthenticationID=1";
myCommand.CommandType = CommandType.Text;
SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
myAdapter.Fill(ds, "Authentication");

rptItems.DataSource = ds;
rptItems.DataBind();
}
protected void rptItems_ItemCommand(object source, RepeaterCommandEventArgs e)
{
LoadData();
}

protected void Button1_Click(object sender, EventArgs e)
{

}
}



I attempted to specify the code bellow:


String[] status = { "Enabled", "Disabled" };
DropDownList1.DataSource = status;
DropDownList1.DataBind();


In my Page_Load function and I got an error saying:


Error 1 The name 'DropDownList1' does not exist in the current context C:\Documents and Settings\solomon\My Documents\Visual Studio 2005\WebSites\WebSite4\ModifyUserRegistration.aspx.cs 17 9 C:\...\WebSite4\


How do I solve the problem?.


Your help is kindly appreciated.


Regards.

Orc Scorcher
02-04-2007, 07:25 AM
Not tested, no guarantees:DropDownList ddl = FindControl("DropDownList1") as DropDownList;
ddl.DataSource = ...