Good morning all,
I am sure this has been asked but I did not see anything.
I have a datalist control. In the edititemtemplat e I have a dropdownlist.
I know on the itemdatabound event is where I can set the dropdownlist
selectedindex. How do I set the correct value?
private void lstDegrees_Item DataBound(objec t sender, DataListItemEve ntArgs
e)
{
DataList dl = (DataList)sende r;
if(e.Item.ItemT ype == ListItemType.Ed itItem)
{
DropDownList ddl = (DropDownList)e .Item.FindContr ol("ddlState") ;
ddl.DataSource = GetStatesLookup ();
ddl.DataTextFie ld = "Abbreviati on";
ddl.DataValueFi eld = "StateID";
ddl.DataBind();
ddl.SelectedInd ex = ddl.Items.Index Of(ddl.Items.Fi ndByText("AL")) ;
//how do I get what the correct value from the datalist datasource? The
field is StateID
}
}
Any suggestions? Thanks to everyone who responds.
Regards,
Chris 4 15996
After setting the SelectedIndex property, SelectedValue should get you the
value (in this case, StateID) for the selected item.
"Chris Kettenbach" <c_**********@h otmail.com> wrote in message
news:ld******** ************@gi ganews.com...
Good morning all,
I am sure this has been asked but I did not see anything.
I have a datalist control. In the edititemtemplat e I have a dropdownlist.
I know on the itemdatabound event is where I can set the dropdownlist
selectedindex. How do I set the correct value?
private void lstDegrees_Item DataBound(objec t sender, DataListItemEve ntArgs
e)
{
DataList dl = (DataList)sende r;
if(e.Item.ItemT ype == ListItemType.Ed itItem)
{
DropDownList ddl = (DropDownList)e .Item.FindContr ol("ddlState") ;
ddl.DataSource = GetStatesLookup ();
ddl.DataTextFie ld = "Abbreviati on";
ddl.DataValueFi eld = "StateID";
ddl.DataBind();
ddl.SelectedInd ex = ddl.Items.Index Of(ddl.Items.Fi ndByText("AL")) ;
//how do I get what the correct value from the datalist datasource? The
field is StateID
}
}
Any suggestions? Thanks to everyone who responds.
Regards,
Chris
Chris,
It's easier than that.
ddl.SelectedVal ue = "AL"
SelectedValue gets the value of the item in the list control or selects the
item in the list control that contains the selected value.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Chris Kettenbach" <c_**********@h otmail.com> wrote in message
news:ld******** ************@gi ganews.com... Good morning all, I am sure this has been asked but I did not see anything. I have a datalist control. In the edititemtemplat e I have a dropdownlist. I know on the itemdatabound event is where I can set the dropdownlist selectedindex. How do I set the correct value?
private void lstDegrees_Item DataBound(objec t sender, DataListItemEve ntArgs e)
{ DataList dl = (DataList)sende r; if(e.Item.ItemT ype == ListItemType.Ed itItem) { DropDownList ddl = (DropDownList)e .Item.FindContr ol("ddlState") ; ddl.DataSource = GetStatesLookup (); ddl.DataTextFie ld = "Abbreviati on"; ddl.DataValueFi eld = "StateID"; ddl.DataBind(); ddl.SelectedInd ex = ddl.Items.Index Of(ddl.Items.Fi ndByText("AL")) ; //how do I get what the correct value from the datalist datasource? The field is StateID }
} Any suggestions? Thanks to everyone who responds.
Regards,
Chris
I am sorry. "AL" is just an example. I want the dropdownlist selected
value to be what the of the StateID was in the datalist datasource. Is
there a way to do that?
In vb.net you use
ddl.SelectedInd ex =
ddl.Items.Index Of(ddl.Items.Fi ndByText(sender .datasource("St ateID")))
how do I accomplish this in C#?
"S. Justin Gengo" <justin@[no_spam_please]aboutfortunate. com> wrote in
message news:ug******** ******@TK2MSFTN GP11.phx.gbl... Chris,
It's easier than that.
ddl.SelectedVal ue = "AL"
SelectedValue gets the value of the item in the list control or selects the item in the list control that contains the selected value.
-- Sincerely,
S. Justin Gengo, MCP Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order." Nietzsche "Chris Kettenbach" <c_**********@h otmail.com> wrote in message news:ld******** ************@gi ganews.com... Good morning all, I am sure this has been asked but I did not see anything. I have a datalist control. In the edititemtemplat e I have a dropdownlist. I know on the itemdatabound event is where I can set the dropdownlist selectedindex. How do I set the correct value?
private void lstDegrees_Item DataBound(objec t sender, DataListItemEve ntArgs e)
{ DataList dl = (DataList)sende r; if(e.Item.ItemT ype == ListItemType.Ed itItem) { DropDownList ddl = (DropDownList)e .Item.FindContr ol("ddlState") ; ddl.DataSource = GetStatesLookup (); ddl.DataTextFie ld = "Abbreviati on"; ddl.DataValueFi eld = "StateID"; ddl.DataBind(); ddl.SelectedInd ex = ddl.Items.Index Of(ddl.Items.Fi ndByText("AL")) ; //how do I get what the correct value from the datalist datasource? The field is StateID }
} Any suggestions? Thanks to everyone who responds.
Regards,
Chris
Chris,
It's the same thing. Get the name of the selection from the list and use:
string Selection;
Selection = [Selection from datasource here];
ddl.SelectedVal ue(Selection);
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Chris Kettenbach" <c_**********@h otmail.com> wrote in message
news:cq******** *************** *******@giganew s.com... I am sorry. "AL" is just an example. I want the dropdownlist selected value to be what the of the StateID was in the datalist datasource. Is there a way to do that?
In vb.net you use
ddl.SelectedInd ex = ddl.Items.Index Of(ddl.Items.Fi ndByText(sender .datasource("St ateID")))
how do I accomplish this in C#?
"S. Justin Gengo" <justin@[no_spam_please]aboutfortunate. com> wrote in message news:ug******** ******@TK2MSFTN GP11.phx.gbl... Chris,
It's easier than that.
ddl.SelectedVal ue = "AL"
SelectedValue gets the value of the item in the list control or selects the item in the list control that contains the selected value.
-- Sincerely,
S. Justin Gengo, MCP Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order." Nietzsche "Chris Kettenbach" <c_**********@h otmail.com> wrote in message news:ld******** ************@gi ganews.com... Good morning all, I am sure this has been asked but I did not see anything. I have a datalist control. In the edititemtemplat e I have a dropdownlist. I know on the itemdatabound event is where I can set the dropdownlist selectedindex. How do I set the correct value?
private void lstDegrees_Item DataBound(objec t sender, DataListItemEve ntArgs e)
{ DataList dl = (DataList)sende r; if(e.Item.ItemT ype == ListItemType.Ed itItem) { DropDownList ddl = (DropDownList)e .Item.FindContr ol("ddlState") ; ddl.DataSource = GetStatesLookup (); ddl.DataTextFie ld = "Abbreviati on"; ddl.DataValueFi eld = "StateID"; ddl.DataBind(); ddl.SelectedInd ex = ddl.Items.Index Of(ddl.Items.Fi ndByText("AL")) ; //how do I get what the correct value from the datalist datasource? The field is StateID }
} Any suggestions? Thanks to everyone who responds.
Regards,
Chris
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Calvin |
last post by:
I'm using a DropDownList in Edit Mode of a DataList.
When the user selects to Edit the page, the values of the DataList will jump
not the to current/present selection, but to defaults, even though no
default is set.
How do set it to keep it's current value.
Is it just a case of placing the code in the Edit Handle to find the current
value and then set the selected value to that... before binding the list?
|
by: Ashish Sharma |
last post by:
I have a DropDownList inside a DataList on a page. I want to set the
selectedindex property of the DropDownList to some value.
I bind the DropDownList on the ItemCreated Event of the DataList.
Private Sub DataList1_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
DataList1.ItemCreated
Dim ddl As DropDownList
ddl = CType(e.Item.FindControl("DropDownList1"), DropDownList)
|
by: Shiju Poyilil |
last post by:
Hi !
I have a requirement wherein i am binding a datalist which contains a label
(Caption for the field) and some literal hidden fields and a dropdown list.
When I am binding to the datalist.. only the labels (caption) and the
invisible literal controls are binded..
Now based on the invisible literal control values I get the information from
DB to bind it with each dropdown list (I am doing this in the item databound
event)
Also based on...
|
by: tshad |
last post by:
How can I set the size of text in the dropdown list:
<asp:DropDownList ID="ddlQuestionType" runat="server">
<asp:ListItem Value="MS" Text="Multiple Single" />
<asp:ListItem Value="MM" Text="Multiple Multiple" />
<asp:ListItem Value="TF" Text="True/False" />
</asp:DropDownList>
The problem is the text is so much larger than the other text and I tried
inline style as well as using a class and it doesn't seem to change the text
|
by: sling blade |
last post by:
Hi,
I have a dropdownlist in my DataList control and I am trying to set the
SelectedItem property of the dropdownlist so when the datalist displays
the user will see the text in the dropdownlist set to a predetermined
value.
I can set the SelectedItem property easy enough and get the
dropdownlist to work fine just so long as the dropdownlist is just on
the form itself not in a DataList control.
| |
by: Paul L |
last post by:
Hi, I have an issue with the OnSelectedIndexChanged event not firing for a
DropDownList control which is in the ItemTemplate of a DataList.
I have made an exact copy of the DropDownList control, and placed it outside
of the DataList and it fires the event just fine. So it's definitely to do
with it being in a template.
I've managed to reproduce the issue on a small test app, the code and html
is below:
|
by: Antonio D'Ottavio |
last post by:
Good morning,
I've a problem with a dropdownlist located inside any row of a datalist,
I fill both datalist and dropdownlist at runtime, the problem is with the
dropdownlist infact using the event OnItemDataBound I can fill it but it is
impossible for me to load the right selectedItem.Value , infact looking at
the html page produced by the server I've this strange code :
<select name="MyDataCampi:_ctl1:ComboTipoPartita"...
|
by: Kevin |
last post by:
Hi
I need to get the "ItemId" from the selected value of the DropDownList in a
DataList, but i don't known where tu put the <%#
DataBinder.Eval(Container.DataItem, "ItemId"), because if I try to put in
the ID of the DropDownList generate an error. I've used this code, i catch
the SelectedIndexChange.
HTML:
<asp:DataList id="dlDropDownList" runat="server">
<ItemTemplate>
|
by: jnoody |
last post by:
The problem I am having is with the SelectedIndexChanged event not
always firing or the SelectedIndex property not being correct when the
event does fire. The code is below, but here are some details first.
The DropDownList is actually a custom control called
DropDownListWithCommandEvent that inherits from DropDownList. The
reason I have created this is to create a DropDownList that will bubble
a Command event to the containing...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |