Can I use a dropDownList iwithin a Panel?

F

Frank

Hello,

I have some text boxes and 2 drop down lists (DDL) within a panel like so:
Everything updates fine but the values from the DDLs are always the items
selected by default. In other words, the items selected from the DDL do not
show up....only the default selected items do. Any suggestions?


<asp:panel id=Pnl_Address runat="server" width="390"
Height="210px" horizontalalign="Center">
<table id=Table1 height=213 cellspacing=1 cellpadding=1
width=388 border=0>
<tr>
<td colspan=3>
<asp:label id=Label1 runat="server"
Font-Names="Verdana" ForeColor="Black" Font-Size="10px" Font-Bold="True">New
Address:</asp:label></td></tr>
<tr>
<td width=83 height=28>
<asp:label id=LblAddr1 runat="server"
Font-Names="Verdana" Font-Size="10px">Addr:</asp:label></td>
<td width=141 height=28>
<asp:textbox id=TbAddr1 tabIndex=1 runat="server"
Height="20px" Font-Size="12px" Width="150px"
BackColor="#DDBA73"></asp:textbox></td>
<td height=28>
<asp:requiredfieldvalidator id=RfvAddr1 runat="server"
ForeColor="Maroon" Font-Size="10px" Font-Bold="True" ErrorMessage="Address
is Required"
EnableClientScript="False"
ControlToValidate="TbAddr1">*</asp:requiredfieldvalidator>
<asp:regularexpressionvalidator id=RevAddr1
runat="server" ForeColor="Maroon" Font-Size="10px" Font-Bold="True"
ErrorMessage="Addr: Enter Only Digits and
Letters!" EnableClientScript="False" ControlToValidate="TbAddr1"
ValidationExpression="[\d\.\ a-zA-Z]{2,60}" font-
names="Verdana">*</asp:regularexpressionvalidator></td></tr>
<tr>
<td width=83>
<asp:label id=LblAddr2 runat="server"
Font-Names="Verdana" Font-Size="10px">Addr2:</asp:label></td>
<td width=141>
<asp:textbox id=TbAddr2 tabIndex=2 runat="server"
Height="20px" Font-Size="12px" Width="150px"
BackColor="#DDBA73"></asp:textbox></td>
<td>
<asp:regularexpressionvalidator id=RevAddr2
runat="server" ForeColor="Maroon" Font-Size="10px" Font-Bold="True"
ErrorMessage="Addr2: Enter Only Digits and
Letters!" EnableClientScript="False" ControlToValidate="TbAddr2"
ValidationExpression="[\d\.\
a-zA-Z]{2,60}">*</asp:regularexpressionvalidator></td></tr>
<tr>
<td width=83>
<asp:label id=LblCity runat="server"
Font-Names="Verdana" Font-Size="10px">City:</asp:label></td>
<td width=141>
<asp:textbox id=TbCity tabIndex=3 runat="server"
Height="20px" Font-Size="12px" Width="150px"
BackColor="#DDBA73"></asp:textbox></td>
<td>
<asp:requiredfieldvalidator id=RfvCity
runat="server" ForeColor="Maroon" Font-Size="10px" Font-Bold="True"
ErrorMessage="City is Required"
EnableClientScript="False"
ControlToValidate="TbCity">*</asp:requiredfieldvalidator>
<asp:regularexpressionvalidator id=RevCity
runat="server" ForeColor="Maroon" Font-Size="10px" Font-Bold="True"
ErrorMessage="Enter Only Letters!" EnableClientScript="False"
ControlToValidate="TbCity" ValidationExpression="^[\ a-zA-Z ]+$"
font-names="Verdana">*</asp:regularexpressionvalidator></td></tr>
<tr>
<td width=83 height=25>
<asp:label id=LblState runat="server"
Font-Names="Verdana" Font-Size="10px">State:</asp:label></td>
<td width=141 height=25>
<asp:dropdownlist id=DdlState tabIndex=4 runat="server" Width="150px"
BackColor="#DDBA73" datatextfield="state_name" datavaluefield="state_abbr"
autopostback="false" > </asp:dropdownlist></td>
<td height=25></td></tr>
<tr>
<td width=83>
<asp:label id=LblPostal runat="server"
Font-Names="Verdana" Font-Size="10px">Postal:</asp:label></td>
<td width=141>
<asp:textbox id=TbPostal tabIndex=5
runat="server" Height="20px" Font-Size="12px" Width="150px"
BackColor="#DDBA73"></asp:textbox></td>
<td>
<asp:requiredfieldvalidator id=RfvPostal
runat="server" ForeColor="Maroon" Font-Size="10px" Font-Bold="True"
ErrorMessage="Postal Code is Required"
EnableClientScript="False"
ControlToValidate="TbPostal">*</asp:requiredfieldvalidator>
<asp:regularexpressionvalidator id=RevPostal
runat="server" ForeColor="Maroon" Font-Size="10px" Width="8px"
Font-Bold="True" ErrorMessage="Postal
Code: Enter Only Digits and Dashes!" EnableClientScript="False"
ControlToValidate="TbPostal" ValidationExpression="[\d-]{5,10}" font-
names="Verdana">*</asp:regularexpressionvalidator></td></tr>
<tr>
<td width=83 height=27>
<asp:label id=LblCountry runat="server"
Font-Names="Verdana" Font-Size="10px">Country:</asp:label></td>
<td width=141 height=27>
<asp:dropdownlist id=DdlCountries tabIndex=6 runat="server" Width="150px"
BackColor="#DDBA73" datatextfield="country_name"
datavaluefield="country_abbr" autopostback="false"></asp:dropdownlist></td>
<td height=27></td></tr>
<tr>
<td width=83></td>
<td align=center width=141>
<asp:button id=Btn_Addr runat="server"
Font-Names="Verdana" ForeColor="Maroon" Font-Size="10px" Text="Submit"
onclick="Edit_Address"
tabindex=7></asp:button>
<asp:button id=Button3 runat="server"
ForeColor="Maroon" Font-Names="Verdana" Font-Size="10px" Text="Cancel"
tabindex=8></asp:button></td>
<td>
<asp:ValidationSummary id=ValidationSummary3
runat="server" ForeColor="Maroon" Font-Names="Verdana" Height="8px"
Font-Bold="True" Font-Size="8px"
Width="136px"></asp:ValidationSummary></td></tr></table></p>
<p align=left>
</asp:panel>





I initialize it in the code behind like so:

dataObj = new
Data_Layer_Afil(ConfigurationSettings.AppSettings.Get("MyConn"));

DdlState.DataSource = dataObj.GetStates(); //the list populates fine

DdlState.SelectedIndex = 0;





When the buttomnn gets clicked, a function gets called and it does this:

string state = DdlState.SelectedValue;

int flag = bizObj.Edit_Address(handle, addr1, addr2, city, state,
postalcode, country);

if(flag == 1) //if successful insert

{

Lbl1.Text = "Success!! Your address has been updated.<br>";

Lbl1.Font.Bold = true;

Pnl_Address.Visible = false;

//Update Repeater

Repeater1.DataSource = bizObj.GetCustomer(Session["handle"].ToString() );

Repeater1.DataBind();



}



Everything updates fine but the values form the DDLs are always the items
selected by default. In other words, the items selected from the DDL do npt
show up....only the default selected items do. Any suggestions?
 
G

Guest

When you hit the submit button, your program pass tru your initializing code
again.
Try putting your initializing code (binding the dropdownlist to the
datasource) inside the ispostback page property:

if(!Page.IsPostBack){
// put ur code here
}

If it doesnt work try to use the dropdownlist.ClearSelection() property.

Ads
Frank said:
Hello,

I have some text boxes and 2 drop down lists (DDL) within a panel like so:
Everything updates fine but the values from the DDLs are always the items
selected by default. In other words, the items selected from the DDL do not
show up....only the default selected items do. Any suggestions?


<asp:panel id=Pnl_Address runat="server" width="390"
Height="210px" horizontalalign="Center">
<table id=Table1 height=213 cellspacing=1 cellpadding=1
width=388 border=0>
<tr>
<td colspan=3>
<asp:label id=Label1 runat="server"
Font-Names="Verdana" ForeColor="Black" Font-Size="10px" Font-Bold="True">New
Address:</asp:label></td></tr>
<tr>
<td width=83 height=28>
<asp:label id=LblAddr1 runat="server"
Font-Names="Verdana" Font-Size="10px">Addr:</asp:label></td>
<td width=141 height=28>
<asp:textbox id=TbAddr1 tabIndex=1 runat="server"
Height="20px" Font-Size="12px" Width="150px"
BackColor="#DDBA73"></asp:textbox></td>
<td height=28>
<asp:requiredfieldvalidator id=RfvAddr1 runat="server"
ForeColor="Maroon" Font-Size="10px" Font-Bold="True" ErrorMessage="Address
is Required"
EnableClientScript="False"
ControlToValidate="TbAddr1">*</asp:requiredfieldvalidator>
<asp:regularexpressionvalidator id=RevAddr1
runat="server" ForeColor="Maroon" Font-Size="10px" Font-Bold="True"
ErrorMessage="Addr: Enter Only Digits and
Letters!" EnableClientScript="False" ControlToValidate="TbAddr1"
ValidationExpression="[\d\.\ a-zA-Z]{2,60}" font-
names="Verdana">*</asp:regularexpressionvalidator></td></tr>
<tr>
<td width=83>
<asp:label id=LblAddr2 runat="server"
Font-Names="Verdana" Font-Size="10px">Addr2:</asp:label></td>
<td width=141>
<asp:textbox id=TbAddr2 tabIndex=2 runat="server"
Height="20px" Font-Size="12px" Width="150px"
BackColor="#DDBA73"></asp:textbox></td>
<td>
<asp:regularexpressionvalidator id=RevAddr2
runat="server" ForeColor="Maroon" Font-Size="10px" Font-Bold="True"
ErrorMessage="Addr2: Enter Only Digits and
Letters!" EnableClientScript="False" ControlToValidate="TbAddr2"
ValidationExpression="[\d\.\
a-zA-Z]{2,60}">*</asp:regularexpressionvalidator></td></tr>
<tr>
<td width=83>
<asp:label id=LblCity runat="server"
Font-Names="Verdana" Font-Size="10px">City:</asp:label></td>
<td width=141>
<asp:textbox id=TbCity tabIndex=3 runat="server"
Height="20px" Font-Size="12px" Width="150px"
BackColor="#DDBA73"></asp:textbox></td>
<td>
<asp:requiredfieldvalidator id=RfvCity
runat="server" ForeColor="Maroon" Font-Size="10px" Font-Bold="True"
ErrorMessage="City is Required"
EnableClientScript="False"
ControlToValidate="TbCity">*</asp:requiredfieldvalidator>
<asp:regularexpressionvalidator id=RevCity
runat="server" ForeColor="Maroon" Font-Size="10px" Font-Bold="True"
ErrorMessage="Enter Only Letters!" EnableClientScript="False"
ControlToValidate="TbCity" ValidationExpression="^[\ a-zA-Z ]+$"
font-names="Verdana">*</asp:regularexpressionvalidator></td></tr>
<tr>
<td width=83 height=25>
<asp:label id=LblState runat="server"
Font-Names="Verdana" Font-Size="10px">State:</asp:label></td>
<td width=141 height=25>
<asp:dropdownlist id=DdlState tabIndex=4 runat="server" Width="150px"
BackColor="#DDBA73" datatextfield="state_name" datavaluefield="state_abbr"
autopostback="false" > </asp:dropdownlist></td>
<td height=25></td></tr>
<tr>
<td width=83>
<asp:label id=LblPostal runat="server"
Font-Names="Verdana" Font-Size="10px">Postal:</asp:label></td>
<td width=141>
<asp:textbox id=TbPostal tabIndex=5
runat="server" Height="20px" Font-Size="12px" Width="150px"
BackColor="#DDBA73"></asp:textbox></td>
<td>
<asp:requiredfieldvalidator id=RfvPostal
runat="server" ForeColor="Maroon" Font-Size="10px" Font-Bold="True"
ErrorMessage="Postal Code is Required"
EnableClientScript="False"
ControlToValidate="TbPostal">*</asp:requiredfieldvalidator>
<asp:regularexpressionvalidator id=RevPostal
runat="server" ForeColor="Maroon" Font-Size="10px" Width="8px"
Font-Bold="True" ErrorMessage="Postal
Code: Enter Only Digits and Dashes!" EnableClientScript="False"
ControlToValidate="TbPostal" ValidationExpression="[\d-]{5,10}" font-
names="Verdana">*</asp:regularexpressionvalidator></td></tr>
<tr>
<td width=83 height=27>
<asp:label id=LblCountry runat="server"
Font-Names="Verdana" Font-Size="10px">Country:</asp:label></td>
<td width=141 height=27>
<asp:dropdownlist id=DdlCountries tabIndex=6 runat="server" Width="150px"
BackColor="#DDBA73" datatextfield="country_name"
datavaluefield="country_abbr" autopostback="false"></asp:dropdownlist></td>
<td height=27></td></tr>
<tr>
<td width=83></td>
<td align=center width=141>
<asp:button id=Btn_Addr runat="server"
Font-Names="Verdana" ForeColor="Maroon" Font-Size="10px" Text="Submit"
onclick="Edit_Address"
tabindex=7></asp:button>
<asp:button id=Button3 runat="server"
ForeColor="Maroon" Font-Names="Verdana" Font-Size="10px" Text="Cancel"
tabindex=8></asp:button></td>
<td>
<asp:ValidationSummary id=ValidationSummary3
runat="server" ForeColor="Maroon" Font-Names="Verdana" Height="8px"
Font-Bold="True" Font-Size="8px"
Width="136px"></asp:ValidationSummary></td></tr></table></p>
<p align=left>
</asp:panel>





I initialize it in the code behind like so:

dataObj = new
Data_Layer_Afil(ConfigurationSettings.AppSettings.Get("MyConn"));

DdlState.DataSource = dataObj.GetStates(); //the list populates fine

DdlState.SelectedIndex = 0;





When the buttomnn gets clicked, a function gets called and it does this:

string state = DdlState.SelectedValue;

int flag = bizObj.Edit_Address(handle, addr1, addr2, city, state,
postalcode, country);

if(flag == 1) //if successful insert

{

Lbl1.Text = "Success!! Your address has been updated.<br>";

Lbl1.Font.Bold = true;

Pnl_Address.Visible = false;

//Update Repeater

Repeater1.DataSource = bizObj.GetCustomer(Session["handle"].ToString() );

Repeater1.DataBind();



}



Everything updates fine but the values form the DDLs are always the items
selected by default. In other words, the items selected from the DDL do npt
show up....only the default selected items do. Any suggestions?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top