Displaying an image in Silverlight 3 Datagrid without XAML - silverlight-3.0

I would like display text and an image in a Silverlight 3 datagrid (i.e. First name, last name, picture). There were many examples on the web utilizing DataTemplate and RowDetailsTemplate in XAML. However, I need to do this all through C# code. Any examples would be highly appreciated.
Thanks,
Sam

Sam,
Steps I'd take:
On your datagrid, set AutoGenerateColumns = false;
Create the columns for text columns and add them to datagrid.Columns
Create a DataTemplateColumn
Assign the DataTemplateColumn .CellTemplate property to the results of a method that looks something like this:
public DataTemplate Create()
{
return (DataTemplate)XamlReader.Load(
#"<DataTemplate
xmlns=""http://schemas.microsoft.com/client/2007"">
<Image Source=""{Binding <your field here>}""/>
</DataTemplate>"
);
}
Bind your grid to your datasource.
That should do it.

Related

List / Repeater component for Vaadin

In my previous project, I've used BeanItemContainer and a Table with GeneratedColumns to simply display a custom component that displays a search result, like google. Title, date, content in a vertical fashion.
As horrible as it was (table) it worked.
Now I want to utilize Grid component for a new project, with the same objective.
The column will be generated and contain a custom component.
Will this work with Grid? is there something better, like a list or repeater component available? Any example of a single column with custom component?
It seems like Vaadin frowns on anything other than simple data or Button renderers.
Update
It looks like adding components don't work out of the box with Grid 7.5+
Also, Grid cells like to be only be fixed hight
ComponentRederer Add-on support cell components, however fix height is still an issue.
Sample code:
public class Result {
String title;
Date date;
URL url;
String description;
List<String> tags;
public Result (){}
}
BeanItemContainer<Result> resultContainer = fetchResults(searchTerm);
I also use a Lazy Container too, beanitem used for simplicity.
I then have a RecordResultComponent that constructs the layout of a single record result in the follow layout:
Title(link with Url)
Date
Description
tag1 tag2 tag3 ...
You can use a Grid alongwith a GeneratedPropertyContainer.
Then, you can use a HtmlRenderer on the custom column.
I hope it helps. :-)

Databinding MVC Grid

I am new to MVC architecture. I want to display MVC grid on my page but through databinding.
So currently in my controller I have created a list which I am returning to View.
Dim lst As New List(Of Employee)
.
.
Return View(lst)
In my View I have this code -->
#code
#Html.Grid(Model).Named("grdGrid").Sortable(True).Columns(Function(col) col.Add(Function(o) o.Id)).Columns(Function(col) col.Add(Function(o) o.EmpName))
End Code
So here I am able to display the grid correctly.
On similar basis, is it possible to databind the grid?
If I am getting my code in a data table, and that data table I want to directly bind to my MVC Grid. I do not want to use list.
Thanks
Amruta
Please refer to this blog post to render the pages with partial view.
Posting a link because there might be many pros & cons in your code but you'll get better idea from the link I posted.

searchable grid using knockout in mvc

I need solution for my problem on urgent basis, I am new with mvc, knockout please provide me sample code for my problem. any help will be highly appreciated.
suppose I have an observable array in my viewmodel i.e
var viewmodel = {
vendorproviders : ko.observablearray([])
}
where vendorproviders list consist of multiple attributes like id, name, country, address etc
I want to populate that array in my grid where each row will have a select button, when that button is clicked it should post the id to my controller action either by submitting or by ajax call.
Furthor more that grid should be searchable like if there is a separate text box, based on the value of text box grid should display matching providers else display all providers.
when user search for particular provider grid should populate from observable array instead of making call at server again and again to pupulate the observable array.
I would suggest starting here.
http://learn.knockoutjs.com/#/?tutorial=intro
What you are talking about is all the basic functionality of the tools you referenced.

Caliburn Micro Update RowDetails of a Datagrid

Let me explain my problem. I am working with Caliburn Micro and have a datagrid where a ObservableCollection is being binded as an Itemsource:
private static ObservableCollection<Models.GamesProperties> _dgGames;
public ObservableCollection<Models.GamesProperties> DgGames
{
get { return _dgGames; }
set
{
_dgGames = value;
NotifyOfPropertyChange(() => DgGames);
}
}
So, when I load my data from my database, the collection will be filled and binded to my datagrid (called DgGames)
Everything is fine so far. I have defined for each DataRow "DataRowDetails". Contains an ImageSource, some TextBlocks and so on. The mentioned collection above contains also those DataRowDetails.
I have now created another View and ViewModel for a dialog window in order to change the DataRowDetails. It does work, but the datagrid (DgGames) won't apply these changes. It does not show any update i have done to the collection. What am I missing ?
Thanks in advance to those who can help me.
If you need more information, feel free to ask.
In order to see modification on the fly in the grid too, Models.GamesProperties has to implemen properly INotifyPropertyChanged. Since you are using Caliburn, you probably want to derive it from PropertyChangedBase.

How to insert drop down list box in a Telerik grid

I have a Telerik Grid, with two columns I need to keep second column as drop-down list box with in the grid, I am using ASP.NET MVC control
Can any body tell me how to do this?
I need to do that for my project.
Here is how I did it:
columns.Bound(o => o.Role).ClientTemplate(
Html.Telerik().DropDownList()
.Name("RoleList<#= UserID #>")
.BindTo(new SelectList(UserController.GetRoles()))
.ToHtmlString()
);
The static method GetRoles returns a simple IEnumerable of String. You still can return a custom object by using a different SelectList constructor to specify Value and Text property of your custom object.
new SelectList(UserController.GetCustomRoles(), "RoleID", "ShortName")
You can set the template of the column to embed arbitrary HTML. If using Ajax binding - try the client template. The following online examples will be helpful:
Server templates
Client templates

Resources