DropDownList DataValue as object - asp.net

DataTextField="Name"
DataValueField="ID_ListGroupParIzm"
???? DataValueField2="ID_Point"
is it real to load 2 values from sqlDataSource in one DropDown list ? Get structure object from sqlDataSource ?
I can see only one way - making a new table to combine ID_Point and ID_ListGroupParIzm to one ID but that's really weird.

The only reason I can see for trying to do this is so that you can use javascript to affect two other objects on the page when something is selected.
If that is the case, I would strongly suggest using css classes instead and using jQuery (or another similar framework to select them from the dom.
eg.
<div id="ctl00_point" class="point item1">Content</div>
<div id="ctl00_listgrouppartzm" class="lgpartzm item1">Content</div>
<div id="ctl01_point" class="point item2">Content</div>
<div id="ctl01_listgrouppartzm" class="lgpartzm item2">Content</div>
Now rather than trying to store "point1|listgrouppartzm1" into the value of the drop down list and then parse it out, you only have to store "item1" and you have all the information you need to find those two divs.
In jQuery, you can get them both by
$(".item1")
or individually by
$(".item1.point")
$(".item1.lgpartzm")

You need to combine two fields before data-binding to the dropdownlist.
I think it's the only way to do it.

Related

Binding using data-win-bind to backgroundImageUrl

I'm trying to bind the background-img: url('') property in a WinJS application.
I've got a view model property which is set to something dynamic like:
'images/' + myObject.name + '.jpg'
But I'm unsure how to use data-win-bind to set said property to the css property background-img: url(''); correctly.
My template is currently set like this:
<div class="item" data-win-bind="style.backgroundImage: backgroundImageUrl">
Where backgroundImageUrl is my view model property, but this does not seem to setting things correctly.
Any ideas as to how to bind to these properties?
Your data-win-bind syntax looks correct. So there could be two possibilities.
First, make sure you've called WinJS.Binding.processAll. That's necessary to set the binding context and set up the bindings described by data-win-bind attributes. Nothing happens without it.
Second, the value of the source's backgroundImageUrl must be a string in the form that CSS expects, that is, "url('')". It can't just be the relative path itself, like you would use with an img.src target.
To do this, either make the source's property in that form, or use a binding initializer/converter to add the url('') part automatically. For more on that, I suggest looking at Chapter 6 of my free ebook, Programming Windows Store Apps with HTML, CSS, and JavaScript, 2nd Edition, with the general data-binding discussion starting on page 299 and the initializer stuff starting on page 315.

Kendo UI Grid View Doesn't re-bind data- attributes

I am using Kendo-UI's Grid along with the knockout-kendo scripts and I've come across a problem that I think I'm missing something silly for.
I have a few links posted in one of the grid columns, and in that I'm using knockout to set some of the attributes including a data- attribute as so:
<a class="copyBooking" data-bind="attr: { 'data-bookingid': BookingId }">Copy</a>
I also have a small piece of Javascript that is set to run when the link is clicked:
$(".copyBooking").click(function(){
var bookingId = $(this).data("bookingid");
//code to access a function via ajax'
});
All seems fine on the initial load as the code within the Javascript runs and my alert comes back with the expected results. However, when I change pages the in Kendo Grid (I have my data paged to only show 10 results at a time) something stops the Javascript from functioning.
According to the HTML generated in Firebug or it's equivalent in Chrome, the data- attribute is set correctly in the HTML, so I'm no sure if the .click isn't firing correctly or if the data- attribute itself isn't being picked up correctly.
Does anyone have any suggestions?
As the element doesn't exist after you page through your grid. You need to have this function run on the databound event so that after the grid is re-rendered it will be applied to the 'new' dom element.
The other option would be to extend your knockout model of your rows with a function and click-bind to that.

Is it bad to add a css class that doesn't exist?

I want to add a bunch of classes to some text fields so i can get their values with jquery. This seems like standard practice when using jQuery and this post suggests it as the answer but how does this affect page loading? Won't it be trying to find all these classes? I have been told in the past to try minimise the amount of classes used on controls.
I have about 12 controls i'll want to add unique classes to to get their value. I am using asp.net so I can't use the id. I also can't use the ClientID as the controls are in a table (but only 1 set of controls will show at any one time).
e.g.
<asp:TextBox ID="txtValue1" runat="server" CssClass="value1" Text='value1' />
<asp:TextBox ID="txtValue2" runat="server" CssClass="value2" Text='value2' />
<asp:TextBox ID="txtValue3" runat="server" CssClass="value3" Text='value3' />
...
var value1 = $('.value1').val();
var value2 = $('.value2').val();
var value3 = $('.value3').val();
And none of the class names will exist in css.
Thanks
Edit:
I know this works but I was more curious about the affect it had on page loading. There was an answer (seems to be deleted now) that said something like the html parser ignores the classes. The css parser will only look at classes that are defined. So it sounds like it would be completely ignored and have no affect on page load. Is this right?
It is okay to use a CSS class that doesn't exist, but if they are unique you want to use id, not class.
You say you are using ASP.Net so you can't use the ID parameter, but you can. In JQuery you can get the controls using the below
var value1 = $('[ID$=yourID]').val();
For more info on JQuery Selectors check out: JQuery Selectors and Attribute Ends With Selector
The above selector basically finds the id ENDING in "yourID" so ignoring all the masterpages extra text at the start. You just have to make sure these are unique. e.g. don't have ids like "HSBC" and "SBC" as the above selector on "SBC" will find both.
I don't think it's a problem. The only times I've had problems with non-existant classes or ID's is one time I had an onclick reference an ID that didn't exist. This messed things up...Other than that I think classes are pretty harmless. I'd be interested to know though..
Any other thoughts??
Which version of asp.net are you using? In asp.net 4.0, you have the ability to use unmangled ids. It looks like the simplest solution would be to set ClientIDMode="Static" to all of your textboxes and then refer by id. Otherwise, sure, I've created classes that don't exist to refer to things.... all the time.
Edit: (in response to your comment about the effect page load).
I think your question about having extra classes in a div that are not currently used is not a bad question (at least in a theoretical sense), and I honestly don't know the precise answer. I do believe any effect is quite minuscule. If you consider best practices to write html, you generally write and structure the HTML, with it's classes, before you write the CSS. This means at the time you write the CSS, certainly some classes will not be used. Indeed, after styling the basic tags (body, h1, a, etc), you may find you never need to create selectors with those classes for some particular design. And yet for the next design, you might need those classes. I'm pretty sure the technology behind CSS was built with those kinds of scenarios in mind, and I bet millions if not billions of pages on the internet follow that exact scenario, especially if they use something like Modernizr, which adds classes to the html element of the page as a way of providing you classes you can select against considering the possible capabilities of the current browser. You may never need those classes, but they are there if you need them.

How can I add properties/attributes to an HTML markup container tag in ASP.Net

I've seen all of the usual pages with information about how to create a sub-tag that allows content within a user control (using ITemplate and INamingContainer) but I've yet to see anyone able to add properties that become attributes to said tags, for example:
<asp:MyControl runat="server" ID="myControlTest" SomeAttribute="SomeValue">
<Content ContentAttribute="Something">
Blah
</Content>
</asp:MyControl>
If you see the ContentAttribute on the Content tag, that is what I'd like to be able to achieve, but if I set it all up using ITemplate and INamingContainer etc, I can add a property that does in fact appear in Intellisense for that tag but when I run the code, it says Content does not have property/attribute named ContentAttribute (it also gives the same as a warning in VS IDE but still allows me to compile it).
I have tried everything to make this work and so far the only way seems to be if I make the Content property on MyControl a class that inherits from System.Web.UI.Control and implements ITemplate. That works but unfortunately I have to specify the runat attribute on the Content tag (because it sees it as a control rather than a sub-tag) and I'd rather not do that if possible.
Hope I have explained this well enough, if I haven't please let me know and I'll do my best to elaborate further.
Thanks in advance.
I think what you're proposing is something like a MIME email where there are a variable number of sections, each with an identifier for the client to choose the best version of the email it can handle. I assume you're wanting to select the appropriate template at runtime, based on that attribute.
The standard .NET controls don't implement that way, so far as I can tell. Think of the Repeater which has:
<asp:Repeater id="myRepeater" runat="server">
<HeaderTemplate>...</HeaderTemplate>
<ItemTemplate>...</ItemTemplate>
<FooterTemplate>...</FooterTemplate>
</asp:Repeater>
Each of the subitems (templates) has a different name, not the same name with a separate attribute.
Is there any way for you to define, ahead of time, what all of the possible sections might be, the way the repeater does?
<asp:MyControl runat="server" ID="myCtlTest">
<SomethingTemplate>Blah</SomethingTemplate>
<OtherTemplate>Blah</OtherTemplate>
</asp:MyControl>
I'm guessing not but wanted to throw it out there in case.
Alternately, could the ContentAttribute move to MyControl? The SETter would then load/build the template for you depending on the value.
<asp:MyControl runat="server" ID="myCtlTest" ContentAttribute="Something">
<Template></Template>
</asp:MyControl>
...or it could be loaded with a method instead of using the property SETter.
If you will always need multiple templates, perhaps a combination of those two concepts would help.
<asp:MyControl runat="server" ID="myControlTest"
SomethingTemplate="Something"
OtherTemplate="Other">
<SomethingTemplate></SomethingTemplate>
<OtherTemplate></OtherTemplate>
</asp:MyControl>

SharePoint list item with checkbox databinding possible?

In SharePoint I can tee up a binding to an edit field like this below. When the form posts back the changes are automatically persisted to the underlying list item.
<PublishingWebControls:RichHtmlField ID="Field1" FieldName="MySPListItemFieldName" ...
So this works great for RichHtmlFields, but say I've got a Yes/No (boolean) field in the same list item, is there a similar construct to bind that field to a check box control in a similar way?
My goal is to not have to throw down a line of c# to transfer the value of the control to the field, I want it to be automatic like RichHtmlField. It seems like there has to be a straight forward way of doing this since SharePoint does this itself with its internal list item editing page (EditForm.aspx).
What you're after is a BooleanField control on your form:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.booleanfield.aspx
Just set the FieldName to that of your Yes/No column, should work fine.

Resources