This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Microsoft XML > December 2003 > Checkbox data binding
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Checkbox data binding
|
|
|
| On one of my web pages I have bounded a check box to an
xml data island field. The updates are happening but if
i click on the checkbox to make a mark appear, the xml
data island gets a value of '-1' instead of the
expected '1'. Does anyone know why this happens?
| |
| David Carnes 2003-12-17, 9:41 am |
| Adam:
-1 is the same as "true," as far as the computer is concerned.
One caveat regarding databinding a checkbox. I had a couple of users report
that the check wouldn't "hold" when they clicked the checkbox. I could
never reproduce the problem at my end, but I was able to solve it by coding
my XML in a different way. Originally, I had the checkbox bound to an
attribute, but if I made it an element, the problem went away.
Example:
<datum id="123" check="0"/>
to
<datum id="123"><check>0</check></datum>
It was a strange, rare occurance, and I happened on the solution quite by
accident.
HTH!
Dave
"Adam" <anonymous@discussions.microsoft.com> wrote in message
news:013301c3c3fb$bfcbd4c0$a301280a@phx.gbl...quote:
> On one of my web pages I have bounded a check box to an
> XML data island field. The updates are happening but if
> i click on the checkbox to make a mark appear, the xml
> data island gets a value of '-1' instead of the
> expected '1'. Does anyone know why this happens?
| |
|
| The problem is that this XML file is then input to
sqlserver through an updategram and sqlserver complains
about the '-1' value. It expects '1', '0', 'true',
or 'false'.quote:
>-----Original Message-----
>Adam:
>-1 is the same as "true," as far as the computer is
concerned.quote:
>
>One caveat regarding databinding a checkbox. I had a
couple of users reportquote:
>that the check wouldn't "hold" when they clicked the
checkbox. I couldquote:
>never reproduce the problem at my end, but I was able to
solve it by codingquote:
>my XML in a different way. Originally, I had the
checkbox bound to anquote:
>attribute, but if I made it an element, the problem went
away.quote:
>Example:
><datum id="123" check="0"/>
>
>to
>
><datum id="123"><check>0</check></datum>
>
>It was a strange, rare occurance, and I happened on the
solution quite byquote:
>accident.
>
>HTH!
>Dave
>
>
>"Adam" <anonymous@discussions.microsoft.com> wrote in
messagequote:
>news:013301c3c3fb$bfcbd4c0$a301280a@phx.gbl...
if[QUOTE][color=darkred]
>
>
>.
>
| |
| David Carnes 2003-12-17, 9:41 am |
| Ah, now I see the violence inherent in the system.
Before you post the XML back to the server, you can always caress it a bit.
1. Select all the nodes that have the checkbox value set to -1, loop
through the list and set their values to something more useful to your
updategram.
2. Create an XSLT stylesheet and pass your XML though it.
3. In script, code the onchange event to select the node and change the
value to true/false.
#3 will be the most amount of work. #2 might not be convenient (I've
encountered issues when tranforming a data island (which defaults to MSXML3)
with an MSXML4 stylehsheet). So, #1:
You can access the data island as a DOM document (testXML is the ID of the
data island).
function test(){
var nodeList = testXML.XMLDocument.selectNodes("//*[@checked='-1]");
var t;
for(t = 0; t < nodeList.length; t++){
nodeList.item(t).attributes.getNamedItem("value").nodeValue = "1";
}
alert(testXML.XMLDocument.xml);
}
I used a very generic XPath for the selectNodes(); modify to your heart's
content; mileage will vary.
HTH!
Dave
<anonymous@discussions.microsoft.com> wrote in message
news:026501c3c412$3d6bb470$a401280a@phx.gbl...[QUOTE][color=darkred]
> The problem is that this XML file is then input to
> sqlserver through an updategram and sqlserver complains
> about the '-1' value. It expects '1', '0', 'true',
> or 'false'.
> concerned.
> couple of users report
> checkbox. I could
> solve it by coding
> checkbox bound to an
> away.
> solution quite by
> message
> if
| |
| David Carnes 2003-12-17, 9:41 am |
| Oops, typo:
var nodeList = testXML.XMLDocument.selectNodes("//*[@checked='-1]");
var t;
for(t = 0; t < nodeList.length; t++){
nodeList.item(t).attributes.getNamedItem("checked").nodeValue = "1";
}
Ciao,
Dave
| |
|
| :-\ I was hoping there would be an easier way. Thanks
for your help Dave.
-- Adam
quote:
>-----Original Message-----
>Oops, typo:
>
> var nodeList = testXML.XMLDocument.selectNodes("//*
[@checked='-1]");quote:
> var t;
> for(t = 0; t < nodeList.length; t++){
> nodeList.item(t).attributes.getNamedItem
("checked").nodeValue = "1";quote:
> }
>
>Ciao,
>Dave
>
| |
|
| Since I was already using an xslt to transform the data
island into the updategram, I thought it wouldn't be too
difficult to add in the boolean() function in the
xsl:select statements. I am using the following:
<xsl:value-of select="boolean(DSOther)" />
(where DSOther is one of my fields containing
value '0'). The node however always transforms to
value 'true'. Whether the original node containts -1 or
0. I have also tried /DSOther (always false)
and //DSOther (always true). I dont think I am using
this function correctly, I think it is seeing the values
as a non-empty string and returning true instead of
reading the values as a number. What I am trying to do
seems like it should be a common and easy thing to do,
but I can't find any specific examples anywhere?!? How
is this function used?
quote:
>-----Original Message-----
>Actually, I think this is the easier way. You can
manipulate the dataquote:
>island just before you send your updategram. (Unless
I've totally madequote:
>incorrect assumptions about your environment.) 5 lines
of code.quote:
>If you need assistance with the XPath to select your
nodes, feel free toquote:
>post to the newsgroup. Basic documentation here: (may
be more than youquote:
>need; I will make another assumption and guess that your
data island is notquote:
>too complex)
>http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/xmlsdk/htm/xpath_ref_overview_0pph.asp?
frame=truequote:
>
>
>Ciao,
>Dave
>8-)
>
>
>.
>
| |
|
| I used a combination of boolean() and number() in my
value-of statement to achieve the expected results.
i.e.
<xsl:value-of select="boolean(number(DSOther))" />
Looks a little clumsy so if you know of a more
streamlined approach, please let me know. Thanks for
your help.
-- Adam
quote:
>-----Original Message-----
>Actually, I think this is the easier way. You can
manipulate the dataquote:
>island just before you send your updategram. (Unless
I've totally madequote:
>incorrect assumptions about your environment.) 5 lines
of code.quote:
>If you need assistance with the XPath to select your
nodes, feel free toquote:
>post to the newsgroup. Basic documentation here: (may
be more than youquote:
>need; I will make another assumption and guess that your
data island is notquote:
>too complex)
>http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/xmlsdk/htm/xpath_ref_overview_0pph.asp?
frame=truequote:
>
>
>Ciao,
>Dave
>8-)
>
>
>.
>
| |
| David Carnes 2003-12-18, 8:45 pm |
| Adam:
Forgive my tardiness; I went to the midnight showing of Return of the King
last night. (Or, as my wife called it, GeekFest 2003.) So I am just
getting coffee in me, and am trying to get my head back into work.
My thought on your XPath and functions is, if it works well and isn't (too)
slow, then go for it. I imagine that the number() is required because the
value from your checkbox is stored as a string. The only thing that comes
to mind that *might* work better would be to define a schema that demands
that the value is an integer. But you'd still have to call the boolean(),
and the overhead and extra coding time to deal with a schema might not be
worth it.
In answer to your previous post, info on the boolean():
http://msdn.microsoft.com/library/d....asp?frame=true
Ciao,
Dave
"Adam" <anonymous@discussions.microsoft.com> wrote in message
news:0ae601c3c4b1$06368e40$a401280a@phx.gbl...[QUOTE][color=darkred]
> I used a combination of boolean() and number() in my
> value-of statement to achieve the expected results.
> i.e.
> <xsl:value-of select="boolean(number(DSOther))" />
> Looks a little clumsy so if you know of a more
> streamlined approach, please let me know. Thanks for
> your help.
>
> -- Adam
>
>
> manipulate the data
> I've totally made
> of code.
> nodes, feel free to
> be more than you
> data island is not
> url=/library/en-us/xmlsdk/htm/xpath_ref_overview_0pph.asp?
> frame=true
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|