Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 20th, 2010, 05:50 AM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Wink displaying dropdown selected value other fields

Hi,

I form my dropdown with xml data. While using datavaluefield for indexing and datavaluetext for dropdown text I still have a few other xml attributes that I want to display on the page reflecting the selected value. Please give me some hints on how I can efficiently accomplish this. Thanks much.

James
  #2 (permalink)  
Old January 20th, 2010, 07:36 AM
Friend of Wrox
 
Join Date: May 2006
Location: Northampton, United Kingdom.
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

I don't know of a way to include anything other and the value and description on the drop down field.

However after an item is selected from the drop down then you have a value that can e used to discover the other relevant information.
Processing need to be performed after selection but this is against the extra data you would read in form the initial xml read. This would ensure the transfer of only the data you need.
  #3 (permalink)  
Old January 20th, 2010, 07:39 PM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default Dispaly relevant fields of selectedItem

Hi,

Included here is my code and I am trying to have a label to display both FirstName and LastName of the selected item. Thanks.
--------------xml-----------------
<?xml version="1.0" encoding="utf-8" ?>
<Employees>
<Employee>
<FirstName>Tom</FirstName>
<LastName>Jones</LastName>
<CustomerId>1</CustomerId>
</Employee>
<Employee>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<CustomerId>2</CustomerId>
</Employee>
</Employees>

--------------xsl-----------------

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="xml" indent="yes"/>

<xsl:template match="Employees">
<Employees>
<xsl:apply-templates select="Employee"/>
</Employees>
</xsl:template>
<xsl:template match="Employee">
<Employee>
<xsl:attribute name="FirstName">
<xsl:value-of select="FirstName"/>
</xsl:attribute>
<xsl:attribute name="CustomerId">
<xsl:value-of select="CustomerId"/>
</xsl:attribute>
</Employee>
</xsl:template>
</xsl:stylesheet>

--------------asp.net----------------

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

//Label label1 = new Label();
label1.Text = DropDownList1.SelectedItem.Text;
}

protected void XmlDataSource1_Transforming(object sender, EventArgs e)
{

}
}
}

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="XmlDataSource1"
DataTextField="FirstName" DataValueField="CustomerId" AutoPostBack="true" ></asp:DropDownList>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/Employees.xml" TransformFile="~/XSLTFile.xsl"></asp:XmlDataSource>

<asp:Label ID="Label1" runat="server" text="Label1" ></asp:Label>

</div>
</form>
</body>
</html>
  #4 (permalink)  
Old January 21st, 2010, 04:00 AM
Friend of Wrox
 
Join Date: May 2006
Location: Northampton, United Kingdom.
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

Ah, I understand now/

You want to concatenant the description from two fields in the xml file.

I know you can do this from a SQLDatasource just by specifiying the two fields in the selection criteria and joining them together with "AS"


In VB the code-behind code to generate the items in the dropdownlist would be

DropDownList1.Items.Add(New ListItem(FirstName & " " & Lastname, CustomerId)


I will try to find some time to see if you can do the same with XML, but can't guarantee when as I'm up to my eyeballs in work.
  #5 (permalink)  
Old January 21st, 2010, 04:50 AM
Friend of Wrox
 
Join Date: May 2006
Location: Northampton, United Kingdom.
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

Does this help?

http://forums.asp.net/t/1163173.aspx
  #6 (permalink)  
Old January 21st, 2010, 05:32 AM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default

sorry to have confused you. actually I don't want all the fields to show in the dropdown and just one field is fine. What I am really after is to have the fields (there are more than two but I just use two in this example) to be displayed in another control i.e. a label on the same page. It does not sound complex but I have not been able to accomplish it in the last 4 days. Your help is much appreciated.
  #7 (permalink)  
Old January 21st, 2010, 06:26 AM
Friend of Wrox
 
Join Date: May 2006
Location: Northampton, United Kingdom.
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

Try this on another page

Code:
<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="True">
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:DropDownList>
<br/>
<br/>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
Then in code behind (VB)

Code:
ProtectedSub DropDownList1_SelectedIndexChanged(ByVal sender AsObject, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Label1.Text = DropDownList1.SelectedValue
EndSub
This will give you an idea how it works.
You can then replace the Label1.Text = DropDownList1.SelectedValue with some code which will trawl through your XML and retrieve the date you want.
The Following User Says Thank You to timeware For This Useful Post:
jtnchang (January 21st, 2010)
  #8 (permalink)  
Old January 21st, 2010, 06:28 PM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default

Hi, you have been most helpful in providing with solution. Can you help me see why the code Label1.text = dropdownlist1.SelectedValue does not react to the change in my dropdown selection change while the code works when I pasted it inside sub page_load? Would you please be kind enough to provide me more specifically with the code displaying just two elements or attributes i.e. LastName and FirstName in my xml. Thanks in advance.
  #9 (permalink)  
Old January 22nd, 2010, 03:45 AM
Friend of Wrox
 
Join Date: May 2006
Location: Northampton, United Kingdom.
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

Can you check you you have

AutoPostBack="True">

on the dropdownlist.

  #10 (permalink)  
Old January 22nd, 2010, 04:50 AM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default

timeware,

You've been extremely helpful and I am almost done with getting my results. Now with I thought it would be easy to get it to return the data I wanted. I have xsl transformed elements into attributes so there are rightly related but I think I need to introduce a key id or whatever the xsl jargon is. And with the key I am hoping it is easy to grab the data with the key id = DropDownList1.SelectedValue. Would be nice if you can help me out for I am already a week into this and people have been impatiently waiting on me. Thanks so much for your relentless help.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to retain selected values from dropdown list?? skhan ASP.NET 3.5 Basics 5 September 1st, 2009 09:13 AM
How to highlight selected dropdown values. sheetm J2EE 0 June 5th, 2007 05:04 AM
selected item in dropdown not saved on postback rathbird ADO.NET 3 March 6th, 2006 08:44 AM
Getting selected item in dropdown to match XML juliaPGATOUR XSLT 1 December 11th, 2003 05:56 AM
Title: dropdown list as selected according to the san_only ASP.NET 1.x and 2.0 Application Design 1 June 4th, 2003 01:55 AM



All times are GMT -4. The time now is 11:37 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.