Posts

Donate

Inline-Block Elements Not Filling Up The Entire Width Of Div Container Using Width Percentage

Image
Hello, I encountered this issue several weeks ago and decided to put the solution here. This pertains to inline-block elements not occupying the entire width of the container. Each element's width is set using percentage instead of pixels. After doing some research, I found a solution here: Display Inline-Block with Widths as Percent with the solution to set the font-size of the container element to 0 and add style box-sizing to border-box. For the child elements, set the default font size. CSS Code .container { margin : 0 0 1em 0; border : 2px solid black; padding : 1em; font-size : 0; box-sizing: border -box; } nav { vertical-align : top ; display : inline - block ; width : 25%; word-wrap: break-word; background-color : lightgray; font-size : 16px; } .column { vertical-align : top ;

WPF DataGrid Set RowBackground Using AlternationCount And DataTriggers

Hi, There was a question raised on how to set the WPF DataGrid RowBackground with AlternationCount (alternating row colors) and DataTriggers without overriding the Alternation count. The fix is to declare a DataGrid.Style that contains settings for RowBackGround and AlternationCount. And in your DataGrid.RowStyle, define the DataTriggers to highlight RowBackground based on a given Value. <DataGrid x:Name= "dgEmployees" HorizontalAlignment= "Left" Margin= "0,0,0,0" VerticalAlignment= "Top" Height= "346" RowHeaderWidth= "0" AutoGenerateColumns= "False" CanUserAddRows= "False" CanUserResizeColumns= "False" CanUserDeleteRows= "False" ScrollViewer.CanContentScroll= "True" VerticalScrollBarVisibility= "Visible" HeadersVisibility= "Column" IsReadOnly= "True" > <DataGrid.Res

Read SQL Server XML Data Type Column In C#.NET

Image
Hi all, In this demo, I have dummy XML files saved to an XML column in a table. The files have the same structure of nodes, except that some files have altered price value of 104.95. The is the structure of the dummy XML file. <catalog> <book id= "bk101" > <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description> An in-depth look at creating applications with XML. </description> </book> <book id= "bk102" > <author>Ralls, Kim</author> <title>Midnight Rain</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-12-16</publish_date> <description> A former architect battles corporate zombies, an ev

XML parsing: line 1, character 38, unable to switch the encoding

Hello all, Given the task at hand that your going to insert XML data into an XML column in SQL Server and you encounter this error "XML parsing: line 1, character 38, unable to switch the encoding", it seems the insertion of XML data failed due to this line here: <?xml version="1.0" encoding="utf-8" ?> . After doing some research, I found a tutorial on how to avoid unicode issues when inserting XML data into an XML column in SQL Server which is the basis of the solution. I just change the Encoding of the stream to UTF8 to match the encoding of the XML file. using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[ "DefaultConnection" ].ConnectionString)) { SqlCommand command = new SqlCommand( "Insert into XMLTable(name, xmlData) values (@name, @xmlData)" , con); con.Open(); string xmlFile = File.ReadAllText(location); using (MemoryStream stream = new MemoryStream()) { using (StreamWrite

Seed Roles And Users To An Existing Database In ASP.NET MVC 5 Using Identity

Image
Hello, In this tutorial, I will demonstrate seeding roles and users to an existing database in an ASP.NET MVC 5 application using Identity framework. For simplicity, I will use a Northwind. This database doesn't have membership tables at all. To begin with, accomplish the steps below: 1. Create an ASP.NET MVC application and then change web.config connectionStrings element to connect to an existing database (Northwind as my example). 2. Under Package Manager Console type PM> Enable-Migrations 3. Under Package Manager Console type PM> Add-Migration ASPMembership * This will create a file Timespan_ASPMembership.cs inside Migrations folder with scripts to create Membership Tables such as AspNetUsers, AspNetRoles and etc. 4. Under Package Manager Console type PM> Update-Database * This will add membership tables to Northwind database. 5. To seed Roles and Users, create a class SeedRolesAndUsers.cs inside Models folder. This class referenc

The term 'Enable-Migrations' is not recognized as the name of a cmdlet

Hello, When I started creating an ASP.NET MVC application in VB.NET and decided to add Membership tables using the Enable-Migrations command in Package Manager Console, I encountered this error 'The term 'Enable-Migrations' is not recognized as the name of a cmdlet'. In C#, I haven't encountered this issue. So, what I did was to Rebuild the project, and then restart Visual Studio IDE. Eureka,the problem was fixed. :-) Cheers! :)

How To Set WPF DataGridCell And DataGridRow Background Color Using Triggers

Hi, There was a question on the forums on how to set the background color of DataGridCell or DataGridRow using XAML without code. I always thought that the solution will be to use code using IValueConverter. After doing some searching on MSDN and google, the answer is straightforward using Triggers. To set the color of DataGridRow, you set the DataGrid.CellStyle just below the DataGrid markup. <DataGrid Grid.Row= "0" Grid.Column= "0" AutoGenerateColumns= "False" CanUserAddRows= "False" Name= "dgStudents" > <DataGrid.CellStyle> <Style TargetType= "{x:Type DataGridCell}" > <Style.Triggers> <DataTrigger Binding= "{Binding Age}" Value= "28" > <Setter Property= "Background" Value= "Gray" ></Setter> </DataTrigger> </Style.Triggers> </Style> </DataGrid.CellStyle> <DataGrid.Columns>

@Html.EnumDropDownListFor() Helper With Html Attributes In ASP.NET MVC

Hello, I did some research on how to use enums as model for DropDownListFor() for a current application and will format it with Bootstrap classes. For ASP.NET MVC 4, it does not have that kind of helper yet. Luckily, I found an article here Creating a DropDownList helper for enums which supports enums as data source. However, it does not have an argument where in you can pass a boostrap class such as form-control. To achieve the desired output, all you need to do is modify the helper and add another parameter for html attributes which will then be used by the DropDownListFor(). public static MvcHtmlString EnumDropDownListFor<TModel, TEnum>( this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TEnum>> expression, object htmlAttributes) { ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); IEnumerable<TEnum> values = Enum.GetValues( typeof (TEnum)).Cast<TEnum>(); IEnumerable<SelectListIte

Model Binding With ASP.NET MVC @Html.ListBoxFor()

Image
Hi, In this tutorial, I will present three ways on model binding with the @Html.ListBoxFor() helper using a ViewModel class and a simple model class. The Index view below has three @Html.ListBoxFor() controls inside a form that will be populated with different ways using MultiSelectList class, List<SelectListItem> , and IEnumerable<CountryInfo> . @using (Html.BeginForm("Index", "Home", FormMethod.Post)) { <div class= "form-group" > <div class= "form-group" > @Html.ListBoxFor(x => x.SelectedPhoneNumbers, Model.phoneNumbers, new { @class = "form-control " }) </div> <div class= "form-group" > @Html.ListBoxFor(x => x.SelectedItemIds, Model.Items, new { @class = "form-control " }) </div> <div class= "form-group" > @Html.ListBoxFor(x => x.Country.SelectedCountry, new MultiSelectList(Model.Country.Countries, "Code", "T

Read Or Parse Or Deserialize JSON Using JavaScriptSerializer Class In C#

Hello, Here's a simple demonstration on how to parse JSON data using .NET's JavaScriptSerializer class. Given the sample JSON data below: { "catalog": { "book": [ { "id": "bk101" , "author": "Gambardella, Matthew" , "title": "XML Developer's Guide" , "genre": "Computer" , "price": "44.95" , "publish_date": "2000-10-01" , "description": "An in-depth look at creating applications with XML." }, { "id": "bk102" , "author": "Ralls, Kim" , "title": "Midnight Rain" , "genre": "Fantasy" , "price": "5.95" , "publish_date": "2000-12-16" , "description": &q

Donate