473,394 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

DropDownList in DataList

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>
<span><%# DataBinder.Eval(Container.DataItem, "ItemName")%></span>
<asp:DropDownList Runat="server" OnSelectedIndexChanged="SetRanking"
AutoPostBack="True">
<asp:ListItem>
1
</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:DataList>

Codebehind:
protected void SetRanking(object sender, System.EventArgs e)
{
DropDownList CurrentDDL;
int SelectedValue;

CurrentDDL = (DropDownList)sender;
SelectedValue = Convert.ToInt32(CurrentDDL.SelectedItem.Text);
//I need some way to get the ItemId to update
}

Thanks
Feb 28 '06 #1
2 3197
You don't need to databind to the selected value, you just get it in the
event handler as myDdl.SelectedValue, where myDdl is obtained as

DropDownList myDdl = sender as DropDownList;

(c# syntax), where sender is the parameter passed to the event handler.

Eliyahu

"Kevin" <@> wrote in message news:ep**************@TK2MSFTNGP11.phx.gbl...
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>
<span><%# DataBinder.Eval(Container.DataItem, "ItemName")%></span>
<asp:DropDownList Runat="server" OnSelectedIndexChanged="SetRanking"
AutoPostBack="True">
<asp:ListItem>
1
</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:DataList>

Codebehind:
protected void SetRanking(object sender, System.EventArgs e)
{
DropDownList CurrentDDL;
int SelectedValue;

CurrentDDL = (DropDownList)sender;
SelectedValue = Convert.ToInt32(CurrentDDL.SelectedItem.Text);
//I need some way to get the ItemId to update
}

Thanks

Feb 28 '06 #2
If you are storing the ID in the datagrid DataKeyField field, then you can do the following to retrieve it:

// Get the item
DataGridItem iItem = sender.NamingContainer as DataGridItem;
// Get the ID from the item
int nID = dg.DataKeys(iItem.ItemIndex)
// do the update ...

Hope this helps.

Sonu Kapoor [MVP
w: www.DotNetSlackers.com
b: www.KapoorSolutions.com/blog

---
Posted via www.DotNetSlackers.com
Feb 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Antonio D'Ottavio | last post by:
Good Morning, In my web page I've a datalist that is sourced by a database, the problem is that I want that one of the column of the datalist contain a dropdownbox that also is sourced by a table...
0
by: Antonio D'Ottavio | last post by:
Good Morning, In my web page I've a datalist that is sourced by a database, the problem is that I want that one of the column of the datalist contain a dropdownbox that also is sourced by a table...
1
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...
0
by: Ashish Sharma | last post by:
I have a drop down list inside a data list on a form like this : <asp:DataList ID="DataList1" runat="server" EnableViewState="False"> <ItemTemplate> <asp:Label ID="lblname" Runat="server"...
2
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.....
3
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...
1
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,...
4
by: Chris Kettenbach | last post by:
Good morning all, I am sure this has been asked but I did not see anything. I have a datalist control. In the edititemtemplate I have a dropdownlist. I know on the itemdatabound event is where I...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.