Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Thursday, March 29, 2012

Set columns in dataGrid

I have this code:
//Perform search

xslt.Transform(new XPathDocument(Server.MapPath("TIPTREECAT.xml")), xslArg,
sw, null);

StringReader sreader = new System.IO.StringReader("<root>" + sw.ToString() +
"</root>");

this.dataSet.ReadXml(sreader);

this.DataGrid.DataSource = dataSet;

this.DataGrid.DataBind();

How can I change colums I want to show in the grids? I want to show less
columns then there are in an xml data.

Thanksset the AutoGenerateColumns property to False. Then create column templates
for each column you want to display. The simplest version if this is the
BoundColumn:

<asp:BoundColumn DataField="FName"></asp:BoundColumn
You can also right-mouse click the datagrid and go to Property Builder.
This utility will help you set up your datagrid.

"Mark Goldin" <markgoldin@.comcast.net> wrote in message
news:eV#EXH0#DHA.3668@.TK2MSFTNGP09.phx.gbl...
> I have this code:
> //Perform search
> xslt.Transform(new XPathDocument(Server.MapPath("TIPTREECAT.xml")),
xslArg,
> sw, null);
> StringReader sreader = new System.IO.StringReader("<root>" + sw.ToString()
+
> "</root>");
> this.dataSet.ReadXml(sreader);
> this.DataGrid.DataSource = dataSet;
> this.DataGrid.DataBind();
>
> How can I change colums I want to show in the grids? I want to show less
> columns then there are in an xml data.
> Thanks
What is "BoundColumn"?

"Bob Boran" <mcsdsmurf@.hotmail.com> wrote in message
news:eEkdDc0#DHA.3220@.TK2MSFTNGP10.phx.gbl...
> set the AutoGenerateColumns property to False. Then create column
templates
> for each column you want to display. The simplest version if this is the
> BoundColumn:
> <asp:BoundColumn DataField="FName"></asp:BoundColumn>
> You can also right-mouse click the datagrid and go to Property Builder.
> This utility will help you set up your datagrid.
>
> "Mark Goldin" <markgoldin@.comcast.net> wrote in message
> news:eV#EXH0#DHA.3668@.TK2MSFTNGP09.phx.gbl...
> > I have this code:
> > //Perform search
> > xslt.Transform(new XPathDocument(Server.MapPath("TIPTREECAT.xml")),
> xslArg,
> > sw, null);
> > StringReader sreader = new System.IO.StringReader("<root>" +
sw.ToString()
> +
> > "</root>");
> > this.dataSet.ReadXml(sreader);
> > this.DataGrid.DataSource = dataSet;
> > this.DataGrid.DataBind();
> > How can I change colums I want to show in the grids? I want to show less
> > columns then there are in an xml data.
> > Thanks
Check the following link for sample and explanation of a boundcolumn. (watch for line wrap
http://samples.gotdotnet.com/quicks...rid.aspx#column

HTH
Suresh

-- Mark Goldin wrote: --

What is "BoundColumn"

"Bob Boran" <mcsdsmurf@.hotmail.com> wrote in messag
news:eEkdDc0#DHA.3220@.TK2MSFTNGP10.phx.gbl..
> set the AutoGenerateColumns property to False. Then create colum
template
> for each column you want to display. The simplest version if this is th
> BoundColumn
>><asp:BoundColumn DataField="FName"></asp:BoundColumn>>> You can also right-mouse click the datagrid and go to Property Builder
> This utility will help you set up your datagrid
>>> "Mark Goldin" <markgoldin@.comcast.net> wrote in messag
> news:eV#EXH0#DHA.3668@.TK2MSFTNGP09.phx.gbl..
>> I have this code
>> //Perform searc
>>>> xslt.Transform(new XPathDocument(Server.MapPath("TIPTREECAT.xml"))
> xslArg
>> sw, null)
>>>> StringReader sreader = new System.IO.StringReader("<root>"
sw.ToString(
>> "</root>")
>>>> this.dataSet.ReadXml(sreader)
>>>> this.DataGrid.DataSource = dataSet
>>>> this.DataGrid.DataBind()
>>>>>>>> How can I change colums I want to show in the grids? I want to show les
>> columns then there are in an xml data
>>>> Thank
>>>>>>

Thursday, March 22, 2012

set local variable with values of a dataset...

How can I set my local variables with a result in a dataset? with a sql-statement I use the sqldatareader but what's the way when i use a xml file?

Thanx!Hi siebengewald

Try this:


Dim ds as DataSet = new DataSet()
ds.readxml(yourpath & yourxmlfile.xml)
dim varLocal as string = ds.tables("yourtablename").row(numberofyourrow).item("itemname").value

It's not the best way to do it, but the shortest :-)
Are you trying to get a single node from your xml file? I'm a little confused as to what you want. Do you want to set a variable to a value from your xml file? If so what you need to do is load your xml file then perform an xpath statement to obtain your value and load it into the variable. It would be something like this..

string myVariable; //Your variable
string xDoc = "mydocument.xml"; //string to the xml document in your system
XmlDocument myDoc = new XmlDocument(); //a xml document declaration
myDoc.Load(xDoc); //loading your xml document

string xpath = "/masterNode/child::subNode"; //xpath query for the node you want. replace MasterNode and subNode with your root and sub root node.

XmlNode myNode = myDoc.SelectSingleNode(xpath); //querying the node
myVariable = myNode.InnerXml; //setting your variable to the node value

This is the simplest form of code to obtain a single node value from an xml file. Hope this helps
Jeffs way is another good solution to do it directly with the XML Classes. Just to note, my example is done with VB.net and Jeffs with C#
i load a dataset:


Dim ProdFile As New FileStream(Server.MapPath("type.xml"), FileMode.Open, FileAccess.Read)
Dim dsProductsData As New DataSet
Dim vProductsView As New DataView
dsProductsData.ReadXml(ProdFile)

If Not IsPostBack Then
DLProdId.DataSource = dsProductsData.Tables(0).DefaultView
DLProdId.DataBind()
Else
vProductsView = New DataView(dsProductsData.Tables(0))
'vProductsView.RowFilter = "id='" & DLProdId.SelectedItem.Text & "'"
GProdDetails.DataSource = vProductsView
GProdDetails.DataBind()
End If

now the result i got is the complete table, so i can only fill a datagrid or dropdownlist. Now is my question, can i set a local string variable to a specific row of a specific record?
Yup, you sure can! Since you have a dataset, you can just reference a record in it by:

txtBox.text = dataset.Tables("TableName").Rows(row#)("FieldName")

try that!
IT WORKS PERFECTLY THANK YOU VERY MUCH!!!