473,395 Members | 1,649 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,395 software developers and data experts.

DropDownList with Custom Content

Hi,

I have a DetailsView with a template field with a dropdownlist added to it.
If the data coming into that field were put into a textbox, it would look
like:
Small|Medium|Large|X-Large.
I need to break that out into dropdownlistitems with each text being the
value also.
I've tried using a ObjectDataSource unsuccesfully. What would be a valid
way of handling this?

Thanks in advance!

Steven
Oct 17 '08 #1
3 1678
Also to be clear....

The DetailsView is bound to a SqlDataSource, there is a nvarchar
field called Choice1 with things such as:
Small|Medium|Large|X-Large
-or-
Red|Black|Yellow|Blue
so instead of binding it to a textbox
Text='<%# Bind("Choice1") %>'
I need it to break it out into a DropDown. It's the same dataset
as the rest of the DetailsView.

Thanks again!

Hi,

I have a DetailsView with a template field with a dropdownlist added to
it.
If the data coming into that field were put into a textbox, it would look
like:
Small|Medium|Large|X-Large.
I need to break that out into dropdownlistitems with each text being the
value also.
I've tried using a ObjectDataSource unsuccesfully. What would be a valid
way of handling this?

Thanks in advance!

Steven

Oct 17 '08 #2
Hi Steven,

From your description you have a field called "Choice1" in your data table.
The data of that field is either "Small|Medium|Large|X-Large" or
"Red|Black|Yellow|Blue". You want to display the data via the DropDownList
in the DetailsView's ItemTemplate. Say the data is
"Small|Medium|Large|X-Large" you want to populate four items with text
"Small", "Medium", "Large", "X-Large". Is my understanding correct?

If so please try following code. In the DataBound event handler of the
DetailsView we can get the reference of the DropDownList and populate it
manually:

Aspx:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AConnectionString %>"
SelectCommand="SELECT * FROM [Table1]"></asp:SqlDataSource>

<asp:DetailsView AllowPaging="true" ID="DetailsView1"
runat="server" AutoGenerateRows="False"
DataSourceID="SqlDataSource1" Height="50px" Width="125px"
ondatabound="DetailsView1_DataBound">
<Fields>
<asp:TemplateField><ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</ItemTemplate></asp:TemplateField>
</Fields>
</asp:DetailsView>

Aspx.cs:
protected void DetailsView1_DataBound(object sender, EventArgs e)
{
DetailsView d=(DetailsView)sender;
DropDownList ddl = d.FindControl("DropDownList1") as
DropDownList;
if (ddl != null)
{
DataRowView drv = (DataRowView)d.DataItem;
string data = drv.Row["Choice1"].ToString();
string[] datalist = data.Split('|');
ddl.DataSource = datalist;
ddl.DataBind();
}
}

Please test my code to see if it works. If my understanding is wrong please
correct me and clarify the scenario.
Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: "EdisonCPP" <Ed*******@newsgroups.nospam>
| References: <#8*************@TK2MSFTNGP06.phx.gbl>
| Subject: Re: DropDownList with Custom Content
| Date: Fri, 17 Oct 2008 16:05:48 -0400
| Lines: 33
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
| X-RFC2646: Format=Flowed; Response
| Message-ID: <OF**************@TK2MSFTNGP04.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: cpe-071-068-080-144.carolina.res.rr.com 71.68.80.144
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSF TNGP04.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:78090
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Also to be clear....
|
| The DetailsView is bound to a SqlDataSource, there is a nvarchar
| field called Choice1 with things such as:
| Small|Medium|Large|X-Large
| -or-
| Red|Black|Yellow|Blue
| so instead of binding it to a textbox
| Text='<%# Bind("Choice1") %>'
| I need it to break it out into a DropDown. It's the same dataset
| as the rest of the DetailsView.
|
| Thanks again!
|
|
| Hi,
| >
| I have a DetailsView with a template field with a dropdownlist added to
| it.
| If the data coming into that field were put into a textbox, it would
look
| like:
| Small|Medium|Large|X-Large.
| I need to break that out into dropdownlistitems with each text being
the
| value also.
| I've tried using a ObjectDataSource unsuccesfully. What would be a
valid
| way of handling this?
| >
| Thanks in advance!
| >
| Steven
| >
|
|
|

Oct 20 '08 #3
Allen,

Thanks! That worked perfectly.
The biggest thing I was missing was being able to get to the
data:

DataRowView drv = (DataRowView)d.DataItem;

Thanks for your help.

Steven
Hi Steven,

From your description you have a field called "Choice1" in your data
table.
The data of that field is either "Small|Medium|Large|X-Large" or
"Red|Black|Yellow|Blue". You want to display the data via the DropDownList
in the DetailsView's ItemTemplate. Say the data is
"Small|Medium|Large|X-Large" you want to populate four items with text
"Small", "Medium", "Large", "X-Large". Is my understanding correct?

If so please try following code. In the DataBound event handler of the
DetailsView we can get the reference of the DropDownList and populate it
manually:

Aspx:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AConnectionString %>"
SelectCommand="SELECT * FROM [Table1]"></asp:SqlDataSource>

<asp:DetailsView AllowPaging="true" ID="DetailsView1"
runat="server" AutoGenerateRows="False"
DataSourceID="SqlDataSource1" Height="50px" Width="125px"
ondatabound="DetailsView1_DataBound">
<Fields>
<asp:TemplateField><ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</ItemTemplate></asp:TemplateField>
</Fields>
</asp:DetailsView>

Aspx.cs:
protected void DetailsView1_DataBound(object sender, EventArgs e)
{
DetailsView d=(DetailsView)sender;
DropDownList ddl = d.FindControl("DropDownList1") as
DropDownList;
if (ddl != null)
{
DataRowView drv = (DataRowView)d.DataItem;
string data = drv.Row["Choice1"].ToString();
string[] datalist = data.Split('|');
ddl.DataSource = datalist;
ddl.DataBind();
}
}

Please test my code to see if it works. If my understanding is wrong
please
correct me and clarify the scenario.
Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

--------------------
| From: "EdisonCPP" <Ed*******@newsgroups.nospam>
| References: <#8*************@TK2MSFTNGP06.phx.gbl>
| Subject: Re: DropDownList with Custom Content
| Date: Fri, 17 Oct 2008 16:05:48 -0400
| Lines: 33
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
| X-RFC2646: Format=Flowed; Response
| Message-ID: <OF**************@TK2MSFTNGP04.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: cpe-071-068-080-144.carolina.res.rr.com 71.68.80.144
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSF TNGP04.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:78090
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Also to be clear....
|
| The DetailsView is bound to a SqlDataSource, there is a nvarchar
| field called Choice1 with things such as:
| Small|Medium|Large|X-Large
| -or-
| Red|Black|Yellow|Blue
| so instead of binding it to a textbox
| Text='<%# Bind("Choice1") %>'
| I need it to break it out into a DropDown. It's the same dataset
| as the rest of the DetailsView.
|
| Thanks again!
|
|
| Hi,
| >
| I have a DetailsView with a template field with a dropdownlist added
to
| it.
| If the data coming into that field were put into a textbox, it would
look
| like:
| Small|Medium|Large|X-Large.
| I need to break that out into dropdownlistitems with each text being
the
| value also.
| I've tried using a ObjectDataSource unsuccesfully. What would be a
valid
| way of handling this?
| >
| Thanks in advance!
| >
| Steven
| >
|
|
|

Oct 20 '08 #4

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

Similar topics

0
by: adam | last post by:
i have custom user control and i'm trying to pass values to custom user control......I need help it seems to me i cannot pass the value to user control from dropdownlist. I have property in a...
2
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit...
0
by: RyanG | last post by:
when the value that determines the filter is databound?? I am trying to make a DropDownList for a set of data that I use a lot throughout my project. So I extended the DropDownList to retrieve...
10
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a...
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,...
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...
5
by: revbart | last post by:
Yep, that's me. I'll bet I've read a hundred articles somewhere or another, but I just can't get the thing to work. I'm working on a custom solution. One of the major UIs includes a calendar-style...
2
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i'm in vs2005 designer view editing a formview's edit template. i have a dropdownlist and i'm trying to bind the SelectedValue to a custom expression. i was wondering if it is possible to...
18
by: Redhairs | last post by:
Is it possible to get DropDownList.SelectedValue in Page_PreInit() event during the postback?
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:
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
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,...

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.