 |
| General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category.
** PLEASE BE SPECIFIC WITH YOUR QUESTION **
When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 10th, 2004, 05:31 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how to set selectedindex
how to set selectedindex in dropdownlist with optional value when i use from datalist in run time (in html code)
|
|

August 10th, 2004, 09:11 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
hi azita,
I didnt get what you mean exactly....
but I think you want to change selectedindex of a dropdownlist according to the
DataList item selected by user..am I right?
--------------------------------------------
Mehdi.:)
|
|

August 10th, 2004, 09:48 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
or you have a DropDownList in your DataList(ItemTemplate) and want to change it's selectedindex ?
--------------------------------------------
Mehdi.:)
|
|

August 10th, 2004, 11:05 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Hey,
In HTML, you have to use javascript to do so by looping through each option and find the right one.
var list = document.getElementById('DropDownList1');
for (var intI = 0; intI < list.options.count -1; intI++) {
if (list.options[intI].value == 'some value') {
list.options[intI].selected = true;
}
}
Something like that (may be a little off). At the server level, you can do:
DropDownList1.SelectedIndex = <value>
Brian
|
|

August 10th, 2004, 11:40 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
its better not to use JavaScript when you deal with datalist object(work in server-side not in client-side using HTML & javascript).
--------------------------------------------
Mehdi.:)
|
|

August 11th, 2004, 07:34 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Hey,
Well, although the server side code is easier, it is still possible to use JavaScript. Because the datalist is similar to the datagrid, where when you select an item and it posts back, it is possible to use javascript, by changing the above code to:
var list = document.getElementById('DropDownList1');
for (var intI = 0; intI < list.options.count -1; intI++) {
if (list.options[intI].value == '<%=DataList1.<whatever control or attribute returns the value>') {
list.options[intI].selected = true;
}
}
But server-side would be the easiest, especially because you are posting back anyway due to the select.
Brian
|
|

August 14th, 2004, 02:54 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by mehdi62b
or you have a DropDownList in your DataList(ItemTemplate) and want to change it's selectedindex ?
--------------------------------------------
Mehdi.:)
|
i have a dropdown list in my datalist(edittemplate) and iwant to change dropdown list value with my value means(i want pass selectedindex value in edit template )
please help me
thanks.
|
|

August 14th, 2004, 03:07 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by mehdi62b
or you have a DropDownList in your DataList(ItemTemplate) and want to change it's selectedindex ?
--------------------------------------------
Mehdi.:)
|
my dear mehdi
hi
i have a dropdown list in my datalist(edittemplate) and iwant to change dropdown list value with my value means(i want pass selectedindex value in edit template from itemtemplate )
please help me
thanks
|
|

August 14th, 2004, 10:44 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
I think I got it what you mean
somewhere like ItemCommand event write below code
Code:
private void DataList1_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
DataList1.EditItemIndex=e.Item.ItemIndex;//make your cell like EditTemplate
((DropDownList)e.Item.FindControl("DropDownList1")).SelectedIndex=newvalue;
//find your dropdownlist in your edititemtemplate and assign new value to it's SelectedIndex
}
--------------------------------------------
Mehdi.:)
|
|

August 16th, 2004, 02:17 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by mehdi62b
I think I got it what you mean
somewhere like ItemCommand event write below code
Code:
private void DataList1_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
DataList1.EditItemIndex=e.Item.ItemIndex;//make your cell like EditTemplate
((DropDownList)e.Item.FindControl("DropDownList1")).SelectedIndex=newvalue;
//find your dropdownlist in your edititemtemplate and assign new value to it's SelectedIndex
}
--------------------------------------------
Mehdi.:)
|
i performed this way but dropdownlist return null value and i dont khow what do i do
|
|
 |