Showing posts with label fill. Show all posts
Showing posts with label fill. Show all posts

Monday, March 26, 2012

Populate array from XML

Hi.
I have a two dimensional array. Is it possible to fill it with xml data?

Thanks,
ShawnOn Wed, 13 Jul 2005 16:43:49 +0200, "Shawn" <bossman100@.hotmail.com>
wrote:

>Hi.
>I have a two dimensional array. Is it possible to fill it with xml data?

I am guessing that the Xml contains two values that you want into the
array? What is the array and do you have a sample of the Xml.

You could also have a look on MSDN about readin XmlDocuments:

http://msdn.microsoft.com/library/d...lNodeReader.asp

Hope this helps

Tom

Saturday, March 24, 2012

Populate dropdown list with XML

How can I fill a dropdown list with XML data. Simplest way please. I would like to user server.mappath to get the data from the file. Is it possible to use a recordset

I need to populate the ID and the value of the record.

Code sample appreciated...thanksPlease see below code, that helps for your question.

Here is the simple XML file, I am using to bind to dropdownlist and name is as Xmlfile.xml


<?xml version="1.0" encoding="utf-8" ?>
<DataList>
<Student>
<Name>Creator</Name >
<Roll>101</Roll >
</Student >
<Student>
<Name>Maintainer</Name >
<Roll>102</Roll >
</Student
</DataList>

and I am using this file to bind with Dropdownlost in page load event. Assuming DropDownList server control name is DropDownList1


Dim Ds As New System.Data.DataSet
Ds.ReadXml("D:\WebSites\VS2005First\XMLFile.xml")

DropDownList1.DataSource = Ds.Tables(0).DefaultView
DropDownList1.DataTextField = "Roll"
DropDownList1.DataValueField = "Name"
DropDownList1.DataBind()

Hope this helps you!
ok that is pretty easy,fist of all u need to populate ur xml data to your datagrid then bind it to ur dropdownlist.

xml file
<root>
<userName>Bob</userName>
<userID>1</userID>
</root
vb.net
'read your data from your datagrid
'assuming ur xml is your root directory
'

Dim ds As DataSet
ds.ReadXml(Server.MapPath("file.xml"))
'bind your dataset to your dropdown list
DropDownList1.DataSource = ds
'assign the element of ur xml to the ddl
DropDownList1.DataTextField = "userName"
DropDownList1.DataValueField = "userID"
DropDownList1.DataBind()

hope that help.Happy coding
Thank you all for replying - I will try the suggestions given

populate FormView fields from a DropDownList

Hi,
I'm trying to build an online form using asp.net and vb.net for the
code behind in Visual Studio 2005.
I want to fill 3 fields in a FormView that's connected to one table
(table1) with information from another table (table2) by choosing the
key field from table2 in a DropDownList.
Table2 has 3 fields with info that doesn't change (name, phone# and
email for about 5 customer service reps). I want each rep to choose
their name in the DropDownList to populate those fields in the
FormView.
I'm connecting to the sql db with an ObjectDataSource.
I'm thinking I just need to put some VB code into the
SelectedIndexChanged event of the ddl, something like:
*something goes here* = DropDownList1.SelectedValue.ToString()
But I'm drawing a blank on what would go to the left of the equal
sign.
Thanks in advance for the help.myFormView.FindControl("myControlId") will find the control if it is in the
template the formview is going to present. Otherwise you may need to do
something like myFormView.EditItemTemplate.FindControl("myControlId").
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"mkidd" <michaelk@.volkcorp.com> wrote in message
news:19842b1a-bab5-4594-aaef-c1cf99efd809@.u10g2000prn.googlegroups.com...
> Hi,
> I'm trying to build an online form using asp.net and vb.net for the
> code behind in Visual Studio 2005.
> I want to fill 3 fields in a FormView that's connected to one table
> (table1) with information from another table (table2) by choosing the
> key field from table2 in a DropDownList.
> Table2 has 3 fields with info that doesn't change (name, phone# and
> email for about 5 customer service reps). I want each rep to choose
> their name in the DropDownList to populate those fields in the
> FormView.
> I'm connecting to the sql db with an ObjectDataSource.
> I'm thinking I just need to put some VB code into the
> SelectedIndexChanged event of the ddl, something like:
> *something goes here* = DropDownList1.SelectedValue.ToString()
> But I'm drawing a blank on what would go to the left of the equal
> sign.
> Thanks in advance for the help.
Thanks, but can you help me with what to do to write the data from the
DropDownList table to the FormView after the FindControl event? I'm
really new at this.
On Jan 14, 9:15 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.org> wrote:
> myFormView.FindControl("myControlId") will find the control if it is in th
e
> template the formview is going to present. Otherwise you may need to do
> something like myFormView.EditItemTemplate.FindControl("myControlId").
> --
> Eliyahu Goldin,
> Software Developer
> Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
> "mkidd" <micha...@.volkcorp.com> wrote in message
> news:19842b1a-bab5-4594-aaef-c1cf99efd809@.u10g2000prn.googlegroups.com...
>
>
>
>
>
>
>
>
>

populate my datagrid RESOLVED

im trying to fill my datagrid but when the page loads in the browser you cant even see it.
wots going on there then here is the code,

Imports System
Imports System.data
Imports System.Data.SqlClient

Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents txt_mobile_number As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_name As System.Web.UI.WebControls.TextBox
Protected WithEvents btn_submit As System.Web.UI.WebControls.Button
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

' declare the data set and data adapters
Private dsUsers As New DataSet
Private daUsers As New SqlDataAdapter



Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



End Sub

Private Sub loadusers()
'connect to database

Dim oSQLConn As SqlConnection = New SqlConnection
oSQLConn.ConnectionString = "Data Source=(local);" & _
"Initial Catalog=Con_Test;" & _
"Integrated Security=SSPI"
oSQLConn.Open()

'databind the infromation

'If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
daUsers.SelectCommand = New SqlCommand("SELECT * from table_user", oSQLConn)
daUsers.Fill(dsUsers, "Mobile")
DataGrid1.DataSource = dsUsers.Tables(0)
DataGrid1.DataBind()
oSQLConn.Close()
'daUsers.Fill(dsUsers)
'DataGrid1.DataSource = dsUsers.Tables(0)

End Sub


End ClassDoes your dataset contain any data ?
If there is no row in the DataTable, you will not see the Datagrid on the page.
im trying to fill my datagrid but when the page loads in the browser you cant even see it.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



End Sub

What else do you expect with an empty Page_Load event :p
ii called loadusers now in the page load an now i am gettin an error that
'invalid object name table_user', thats the table name within Con_test.
:eek2:
Has it been spelt right in the database?
top man mendhank, i know it seemed obvious with the error message but i never would have checked it,
u da man
Not a problem, we all learn... :)