C# - Binding An Xml Node's Children To DropDownList
Nov 30, 2010
I'm trying to bind the contents of a node of XML to a Drop Down List without much success. Initially, the whole XML document is bound to a repeater - this works perfectly, but now I need to display a drop down list based on the children in the "" node, but I get Data at the root level is invalid. Line 1, position 1 error message on the DataBind() method on the dropDownList. The code snippet I'm using is:
IXPathNavigable x = (IXPathNavigable)e.Item.DataItem;
XPathNavigator questionNode = x.CreateNavigator();
string question = questionNode.SelectSingleNode("questionText").ToString();
//string title = xePage.SelectSingleNode("q").InnerText;
Literal questionText = (Literal)e.Item.FindControl("litQuestionText");
questionText.Text = question;
Panel iconDiv = (Panel)e.Item.FindControl("divIcon");
iconDiv.CssClass = string.Format("icon {0}", questionNode.SelectSingleNode("iconType"));
Panel sliderPanel = (Panel)e.Item.FindControl("pnlSlider");
DropDownList answerDropDown = (DropDownList)e.Item.FindControl("ddlAnswer");
TextBox answerText = (TextBox)e.Item.FindControl("txtAnswer");
switch (questionNode.SelectSingleNode("answerType").ToString())
{
case "d":
sliderPanel.Visible = false;
answerText.Visible = false;
answerDropDown.Visible = true;
XmlDataSource answersList = new XmlDataSource();
answersList.Data = questionNode.Select("answers").ToString();
Response.Write(answersList.ToString());
//XPathNodeIterator answers = questionNode.Select("answers");
//answers.AsQueryable();
answersList.ID = questionNode.SelectSingleNode("questionId").ToString();
answerDropDown.DataSource = answersList;
answerDropDown.DataTextField = "@display";....................................
View 1 Replies
Similar Messages:
Mar 28, 2011
Currently,below is my code.
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source= E\SQLEXPRESS;" + "Initial Catalog=k;Integrated Security=SSPI");
SqlDataAdapter adapSel;
string mySQL = "select column_name from information_schema.columns where table_name='examtimetable' '" + dd_list + "'";....
I receive an error "Incorrect syntax near 'System.Web.UI.WebControls.DropDownList'."
View 3 Replies
Dec 8, 2010
Is it possible to have >1 sitemap files so that I can separate section 1 and 2 into two separate sitemap files?
The codes give this error:
Could not find the sitemap node with URL 'Menu1.aspx?node=hardware'.
The .aspx file has:
[Code]....
The Web.sitemap file contains:
[Code]....
[Code]....
View 6 Replies
Feb 18, 2011
how to read selected node and its parent node values for treeview in asp.net in JAVAscript.
View 3 Replies
Oct 19, 2010
I created a sitemap with a treeview navigation in my aspx site. I am hoping someone can show me the code to put in a Masterpage so that when I expand a child node, all other nodes collapse, and when I expand another node, the previous expanded node collapses.
I have an example here of what I am trying to accomplish:
[URL]
I am using asp.net with VB.
I have been scouring the internet looking for a solution, but so far haven't found anything that works.
View 1 Replies
Oct 16, 2012
I'm populating a treeview dynamically. On OnTreeNodePopulate I call a sub and populate the Parent nodes. I do not want to populate the child nodes at this time. Upto this point it works fine.
Now I would like the user to click the parent node and then populate the child node. I tried to use TreeNodeExpanded, but that is called for each parent node, so that didn't work.
View 1 Replies
Mar 31, 2011
<?xml version="1.0" encoding="utf-8"?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<siteMapNode url="~/" title="Úvodní stránka">
<siteMapNode url="Pocitace" title="Počítače" />
<siteMapNode url="Elektronika" title="Elektronika" />
[code]...
View 2 Replies
Mar 25, 2011
I have a view with 1 dropdown generated from Model property and 3 additional dropdowns that are generated from array property
[code]....
The controller method initializes AgentTypeListItems collection + sets default values for AgentType dropdown and 3 dropdowns for the collection:
[code]....
View 2 Replies
Nov 22, 2010
I want to bind a dropdownlist to a database. I did the following coding but it isn't working.
using System;
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;
using System.Data.Odbc;
using System.Data.SqlClient;....
I am getting the error as
at _Default.rebind() in c:Documents and SettingsaMy DocumentsVisual Studio 2008WebSites oolbar1Default.aspx.cs:line 32
bind the dropdownlist to a datasource.I want my dropdownlist to display text from a database column and use the value field for some other purpose later on in code. I am getting the page displayed when i run the project but not able to get the data in dropdownlist
View 3 Replies
Jul 9, 2010
I have a dropdown list which I bind through a datasource. How can I inject a default value to it? My db doesn't have a default value and changes are not permitted!
View 6 Replies
Mar 17, 2011
I have a DropDownList in a DetailsView, which binds a user's 'AllocatedUser' to a user in the Users table. Occasionally, we'll have some mishaps in the database where the user allocated isn't in the users table, which the DropDownList is filled with. In this case the site crashes and we get a 'SelectedValue does not exist in the list of items error'.What I want to do is catch any binding errors like that, and just set the DropDownList index to 0. I've tried something like this:
OnDataBinding='DoesExist("AllocatedUser",<%#Bind("AllocatedUser")%>)'
but it doesn't like the syntax of that.
View 1 Replies
Apr 12, 2010
i have a dropdownlist,which is dynamically binding from the database ............the problem is i want a particular item in the dropdownlist to apper first in the dropdownlist
View 3 Replies
Sep 21, 2010
I need to bind a dropdownlist to multiple column along with the column heading.. the heading should be unselectablesomething similar to thisEach group are in differnet tables..ow can i implement thisits consuming my time..
View 7 Replies
May 7, 2015
I am binding dropdownlist using entity framework in mvc4 while I run the application getting the following error
Unrecognized attribute 'name'.
View 1 Replies
Dec 29, 2013
I have 2 dropdownlist
1-ddlstate
2-ddlcity
when users select Item from ddlstate according to their selected Item from ddlstate,ddlcity bind from database
below is ddlstate_onselectedindexchanged event
protected void ddlstate_OnSelectedIndexChanged(object sender, EventArgs e) {
Bindcity();
}
and in page_load event I put below code
ListItem ItemC = DDLcity.Items.FindByText(_dr["City"].ToString());
if (ItemC != null) {
ItemC.Selected = true;
[code]....
View 1 Replies
Aug 10, 2010
I have 2 dropdown lists on a WebForm. One of them is populated in the page's Page_Load event. This oneworks fine with the following code.
[Code]....
Then, after a value is selected from this list and a date is selected from a DateTime picker, then I click a button which is supposed to populate the 2nd dropdownlist. In the debugger in the button's click event I can see that the dataset is being populated with data, but then the list is never populated after the DataBind() method is run. Here is code from the button's click event.
[Code]....
View 2 Replies
Oct 29, 2010
I have a State class defined like this:
Public Class State
Public Property StateId As Integer
Public Property Name As Dictionary(Of Integer, String)
End Class
Name(x) contains the state name in different languages. I get a collection of State from the method StateManager.GetAllStates() and I want to bind this collection to a DropDownList. The problem is that I can't find how to set the DataTextField property to let's say stateList.Name(1) which is the english name of my state.
Dim stateList As StateCollection = StateManager.GetAllStates()
Me.DataSource = stateList
Me.DataValueField = "StateId"
Me.DataTextField = "Name(1).Value" <-- Problem here
Me.DataBind()
View 2 Replies
Oct 10, 2010
i have a textbox1 and drop down list 1
i am filling drop downlist from Sql datasource and textbox1.text=Dropdownlist1.SelectedItem.Value.ToString()
all working fine but if i set dropdownlist1.visible = false than textbox1.text = empty string I need to hide the dropdownlist1 and in the same time i need the selecteditem of dropdownlist to be in the Textbox1.text
View 2 Replies
Aug 11, 2010
How do I bind a result from a JSON string to a dropdownlist (I have 2 fields), "NAAM" should be DataTextField and "CODE" should be the DataValueField. Using ddl.Items.Add doesn't do the trick.
string:
{"NAAM":["Drenthe","Flevoland","Friesland","Gelderland","Groningen","Limburg","Noord Brabant","Noord Holland","Overijssel","Utrecht","Zeeland","Zuid Holland"],"CODE":["D","X","B","G","A","K","P","L","E","M","S","H"]}
code:
[Code]....
View 1 Replies
Jun 11, 2012
i am loading xml file from url and storing data into my database.i am binding that data with my dropdownlist bt the problem is wheneverr i select any option from ddl...by defaulst it takes the always takes first selected index...i.e value at the zeroth index value.....i really don't know what exactly the problem either the problem is with dropdown or the way i am loading xml file and binding it to dropdown.....below is my cs code.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
[code]...
View 1 Replies
Oct 22, 2010
I'm trying to bind a List<String> to a DropDownList in a user control. I think I'm doing the right thing, but it seems that after my code executes the bindings are cleared. Here's the code for review!
User control:
<asp:DropDownList ID="subjectNameDropDown" runat="server"/>
<asp:DropDownList ID="yearLevelDropDown" runat="server"/>
Auto-generated designed code-behind:
public partial class NewSiteMetadataUserControl {
protected global::System.Web.UI.WebControls.DropDownList subjectNameDropDown;
protected global::System.Web.UI.WebControls.DropDownList yearLevelDropDown;
}
Code-behind:
public partial class NewSiteMetadataUserControl : UserControl
{
protected override void CreateChildControls()
{
subjectNameDropDown = new DropDownList();
yearLevelDropDown = new DropDownList();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
EnsureChildControls();
// Attempt 1
List<String> subjectNames = GetSubjectValues();
foreach (var subjectName in subjectNames)
subjectNameDropDown.Items.Add(subjectName);
subjectNameDropDown.DataBind();
// Attempt 2
List<String> yearLevels = GetYearLevelValues();
yearLevelDropDown.DataSource = yearLevels;
yearLevelDropDown.DataBind();
}
}
Should this approach work? If it should, how can I debug what happens after the code executes?
View 2 Replies
Aug 24, 2010
private void AddDBDataToControl(DataSet app_Support,int count) {
int i = 0; while (count != 0) {
DateTime dt = Convert.ToDateTime(app_Support.Tables[0].Rows[i]["FromDate"].ToString());
//dt=23/08/2010 10:04:00 AM
DropDownList h1 = (DropDownList)GVDate.Rows[i].Cells[1].FindControl("txthour");
h1.SelectedValue = dt.Hour.ToString();
DropDownList m1 = (DropDownList)GVDate.Rows[i].Cells[2].FindControl("txtmin");
m1.SelectedValue = dt.Minute.ToString();
DropDownList h2 = (DropDownList)GVDate.Rows[i].Cells[5].FindControl("txthourto");
DateTime dt2 = Convert.ToDateTime(app_Support.Tables[0].Rows[i]["ToDate"].ToString());
//dt2=28/08/2010 14:25:00 PM
h2.SelectedValue = dt2.Hour.ToString();
DropDownList m2 = (DropDownList)GVDate.Rows[i].Cells[6].FindControl("txtminto");
m2.SelectedValue = dt2.Minute.ToString();
count--; i++; } }
When the function executes
h1.SelectedValue = "10";
and
m1.SelectedValue ="04";
but when it reaches to
count--
h1.SelectedValue takes the value "14"; rather than h1.SelectedValue = "10"; and
h2.SelectedValue = "14";
and
m1.SelectedValue ="25"; rather than m1.SelectedValue ="04"; and
m2.SelectedValue = "25"
View 4 Replies
Jan 15, 2011
Am trying to bind data to a dropdown list on pageload based on a condition. Code explains further below.
public partial class AddExhibit : System.Web.UI.Page {
string adminID, caseIDRetrieved;
DataSet caseDataSet = new DataSet();
SqlDataAdapter caseSqlDataAdapter = new SqlDataAdapter();
string strConn = WebConfigurationManager.ConnectionStrings["CMSSQL3ConnectionString1"].ConnectionString;
protected void Page_Load(object sender, EventArgs e) {
adminID = Request.QueryString["adminID"];
caseIDRetrieved = Request.QueryString["caseID"];
if (caseIDRetrieved != null) {
CaseIDDropDownList.Text = caseIDRetrieved;
//CaseIDDropDownList.Enabled = false;
} else { try { CreateDataSet();
DataView caseDataView = new DataView(caseDataSet.Tables[0]);
CaseIDDropDownList.DataSource = caseDataView;
CaseIDDropDownList.DataBind(); }
catch (Exception ex) {
string script = "<script>alert('" + ex.Message + "');</script>";
} } }
The CreateDataset method that is called in the if..else statement is contains the following code.
private void CreateDataSet() {
SqlConnection caseConnection = new SqlConnection(strConn);
caseSqlDataAdapter.SelectCommand = new SqlCommand("Select CaseID FROM Cases", caseConnection);
caseSqlDataAdapter.Fill(caseDataSet); }
However when I load the page and as usual the condition that is supposed to bid the data is met, the gridview decides to displays as follows. Is it me or its the Datagrid?
View 3 Replies
Oct 28, 2010
So here is the problem , Is it possible to get the "SelectedItem.Text" of a binded dropdownlist? because everytime I'm getting null Even though I'm having
items in the dropdownlist.
I'm getting the items that I want in the dropdownlist but I can't find out which one is selected.
[Code]....
here is my aspx code:
[Code]....
View 3 Replies
Jul 30, 2010
can any one helpout my problem that how to insert more than one space between two strings while binding dropdownlist.
View 3 Replies