:
From your code, I don't really see why you need to populate the dropdown
list in client side, you can do it in server side, and process what you need
after form post back. And you can use ListBox for multiple selection.
Here is the example:
==== ASPX page =========================================
<asp
ropDownList id="DropDownList1" runat="server">
</asp
ropDownList>
<!-- for multiple selection if you need it -->
<asp:ListBox id="ListBox1" runat="server" SelectionMode="Multiple">
</asp:ListBox>
==== Code Behind ========================================
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.ListBox ListBox1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
// initialize
for(int i=0; i<30; i++)
{
// single selectbox
this.DropDownList1.Items.Add(new ListItem(i.ToString(),i.ToString()));
// multiple listbox
this.ListBox1.Items.Add(new ListItem(i.ToString(),i.ToString()));
}
}
else
{
// post back action
// here you can get the value from your dropdown list
// and then you can process based on the value.
string rtnVal = this.DropDownList1.SelectedItem.Value;
string rtnText = this.DropDownList1.SelectedItem.Text;
// or you get multiple selection from a ListBox
// you can doing in a loop, or collect selected items and
// process later
foreach (ListItem item in this.ListBox1.Items)
{
if(item.Selected)
{
// do things here
Message.Text += item.Text + "<br>";
}
}
}
}
:
now my question is ,how can i acces the values of html dropdownlist on server
side ...
eg. if a user at client side changes value say he select 5 number or 7
number out of 29 numbers then the data at server side shoudl be fill in a
table row (if we let us assume that at server side there is a table having a
column whose value changes acording to client side htmldropdownlist number..
eg. if 2 means monday on server side(in a table's row or column) and total
is 30 days in a month and our numbes in htmldropdownlist is 0,......29 at
cleint side showing to user and user select 2 then
monday should be filled at server side table in a row or column....plz J.W.
try it and sned me urs reply with compltee code(must)(thanks once
again)........try once ...waiting for reply here..
:
ya J.W.,my Friend i have done it by myself after writing my query ,,but i
done it using htmlserver ocntrol instead of webserver control ...........
------------------------------------------------------------------------------------------------
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="firstproject.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="
http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script language="javascript">
function fnPopulate()
{
for(var i=0;i<=29;i++)
{
var opt = new Option(i+'',0,0,0);
document.Form1.ddlist1.options[document.Form1.ddlist1.options.length] =
opt;
}
for(var i=0;i<=59;i++)
{
var opt = new Option(i+'',0,0,0);
document.Form1.ddlist2.options[document.Form1.ddlist2.options.length] =
opt;
}
}
</script>
</HEAD>
<body language="javascript" onload="fnPopulate()"
MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<SELECT id="Select1" style="Z-INDEX: 101; LEFT: 158px; POSITION:
absolute; TOP: 192px" name="ddlist1">
<OPTION selected></OPTION>
</SELECT>
<DIV style="DISPLAY: inline; Z-INDEX: 102; LEFT: 58px; WIDTH: 70px;
POSITION: absolute; TOP: 192px; HEIGHT: 15px"
ms_positioning="FlowLayout"><b>Day</b></DIV>
<DIV style="DISPLAY: inline; Z-INDEX: 103; LEFT: 241px; WIDTH: 70px;
POSITION: absolute; TOP: 193px; HEIGHT: 15px"
ms_positioning="FlowLayout"><b>Hour</b></DIV>
<SELECT style="Z-INDEX: 104; LEFT: 318px; POSITION: absolute; TOP: 191px"
name="ddlist2">
<OPTION selected></OPTION>
</SELECT>
</form>
</body>
</HTML>
-------------------------------------------------------------------------------------------------
my code is
:
u r right J.W. but i need multiple values to be filled in it instead of
single value ....when i apply for loop thenerro rcomes out as "OBJECT
EXPECTED"..by urs code i m able to fil only when value in it and that value
is shown on second position on dropdownlist at cleint side and my first
posotion remains blank.. when i clik on dropdownlist at cleint side...
plz see both problems :->1:->......how to apply FOR loop
(i want to fill values from
0,1, up to 29)
:->2:->......how to set my first value on
first
position instead of second
posintion finally
(at present it comes out as
positon 1->blank
positon 2->0(where 0 is my
first value)
and u know that i m inable to fiil morte then one value in
it..so only one value is shown on position2 whether it is 0 or any other
value like 3,4, etc.
i want to generate list like 0,1,2,3,4,5,....uo to 29.......J.W. PLZ SEE IT
MY FRIEND ONCE AGAIN AND AT THIS TIME SEND ME URS CODE OF ASPX PAGE TO CALL
IT ON PAGE LOAD TIME ...AT PRESENT J.W. MY CODE IS
--------------------------------------------------------------------------------------------
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="firstproject.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="
http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script language="javascript">
function fnPopulate()
{
var opt = new Option(0,0,1,1);
document.Form1.ddlist.options[document.Form1.ddlist.options.length] = opt;
var opt = new Option(1,1,1,1);
document.Form1.ddlist.options[document.Form1.ddlist.options.length] = opt;
var opt = new Option(2,2,1,1);
document.Form1.ddlist.options[document.Form1.ddlist.options.length] = opt;
var opt = new Option(3,3,1,1);
document.Form1.ddlist.options[document.Form1.ddlist.options.length] = opt;
}
</script>
</HEAD>
<body language="javascript" onload="fnPopulate()"
MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<SELECT id="Select1" style="Z-INDEX: 101; LEFT: 159px; POSITION:
absolute; TOP: 382px" name="ddlist">
<OPTION selected></OPTION>
</SELECT>
</form>
</body>
</HTML>
--------------------------------------------------------------------------------------------
:
Mm....don't recall there is a add function of a selectbox.......
Maybe try this:
var opt = new Option(text,value,defaultSelected,selected);
selectboxObj.options[selectboxObj.options.length] = opt;
might help............
:
i want to populate dropdownlist(integer values)(0,1,.....29) on client side
using javascript ...i m confused becoz ERROR IS: ->"OBJECT EXPECTED" .. i
want that when poge loads then dropdownlist should be populate at client side
automatically...
---------------------------------------------------------------------------------------------
<script language="javascript">
function fnPopulate()
{
for(int i=0;i<=29;i++)
{
var myValue=document.createElement("<option value='" + i + "'>" + i +
"</option>");
document.Form1.ddlist1.add(myValue);
}
}
}
</script>
--------------------------------------------------------------------------------------------