Showing posts with label listview. Show all posts
Showing posts with label listview. Show all posts

Monday, March 26, 2012

Access nested properties

Hello everyone.
I have the following problem converning listview property binding.:
My classes are:
[DataObject]
public class Obj1 {
...
[DefaultValue ("New name")]
[DataObjectField (false)]
public string Name {
get { return this.name; }
set { this.name = value; }
}
[DataObjectField (false)]
public Obj2 Nested {
get { return this.nested; }
set { this.nested = value; }
}
...
}
and
[DataObject]
public class Obj2 {
...
[DefaultValue ("New name")]
[DataObjectField (false)]
public string Name {
get { return this.name; }
set { this.name = value; }
}
...
}

and then I use the ListView. It loads an array of Obj1 objects and successfully puts them in the listView
Then in my item template I have something like this: ...
<strong id="Strong3" runat="server">
<atlas:Label ID="name" runat="server">
<Bindings>
<atlas:Binding DataPath="Name" Property="text" />
</Bindings>
</atlas:Label>
</strong>
</td>
<td>
<strong id="Strong5" runat="server">
<atlas:Label ID="nested" runat="server">
<Bindings>
<atlas:Binding DataPath="Nested" Property="text" />
</Bindings>
</atlas:Label>
</strong>
The output is as expected : obj1.Name is shown as it is and obj1.Nested is shown as [object].
When I change:
<atlas:Binding DataPath="Nested" Property="text" />
to
<atlas:Binding DataPath="Nested.Name" Property="text" />
I get an empty text.
Any hints for that?
Thanks in advance

I don't think the current JSON serializer serializes the server-side properties to client-side properties. I think it only creates an object with public fields.
The DataPath in Binding only supports properties. The reason why the top-level field _does_ work is that the client-side DataRow overrides getProperty and returns a field (ie. calling myDataRow('Name') returns myDataRow['Name'], which equals to myDataRow.Name).

Access checkbox inside listview...

I have a listview that have a checkBox for each row...

How can I access this checkBox?
I need it checked if that record exists in another listview when it binded..

How can I do this?

Thanx!

You could try solution like this:

When you create your Checkboxes in the destination list - just Name ALL of them like this:

<input type="checkbox" name="RecordCheck" value="123456" />

and in the source list like this:

<input type="checkbox" name="SourceCheck" value="123456" />

, where for the "value" should be applied some "Id" instead of "123456". This way you could run the JavaScript function like this:

function SyncronyzeCheckedItems()
{
var collChecksSource = document.getElementsByName("SourceCheck");
var collChecksDestination = document.getElementsByName("RecordCheck");

for(si = 0; si < collChecksSource.length; si++)
{
for(di = 0; di < collChecksDestination.length; di++)
{
if ( collChecksDestination.item(di).value == collChecksSource.item(si).value )
{
collChecksDestination.item(di).checked =collChecksSource.item(si).checked;
}
}
}

}

Is that what you looked for?


I had found some code that works with grid view, with some little changes it could be used in your scenario.
for (int i = 0; i < gridView1.Rows.Count; i++) { GridViewRow row = gridView1.Rows[i];bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;if (isChecked) {// something here } }

I'll try it...