Tuesday, May 22, 2007

Couldn't find selectedvalue

I'm having problem with GridView again.
I don't know what'd happened.
It worked on last Friday, I was really happy that it finally worked.
But, today when I tested it again, it failed.

I added an edit function to the GridView, and bind the values of the fields to the dropdownlists.
Problem happens after I clicked on the "edit" button on the selected row.
I populated the dropdownlist with a DataSet that was returned from my own function.
DataSource='<#% GetCategories() %>'
I've checked the DataSource passed in correctly, with all the items I want to list out.
But, error returned saying the dropdownlist selected value was not found in the item list.
How could this happen?
The dropdownlist is bond to the correct field.
The weird thing is, I didn't change any codes here.
I'm a bit frustrated now, there are many more work for me to do and problems to solve.
Yet, something was done and now it's undone.

Well, I know frustration won't help to solve the problem.
I will take a break here, and do something else first.
I'll finally find out how to solve this later.
Sometimes, a simple thing but costs lots of effort & thinking.

Monday, May 14, 2007

Crystal Report or Embedded Report?

I need to create a simple report for my application.
The report only needs to include some data in tabular format, and some user information.
I've been looking into Crystal Report and Embedded Report today.

Crystal Report:
I guess the functionality is more powerful, and it's been a well known reporting.
If my report requires more functionality in future, then I do not need to change the report control.

Embedded Report:
I was thinking of choosing this embedded report, coz I only need a simple report.
This embedded report can be run on local mode, which it will be faster and less traffic created to request data from the server.
I only need to export function to PDF and Excel, which this embedded report was limited to only export to Excel and PDF works fine for me.

Well, so far I have problems with these two report tools, although I thought it should be very simple.
Crystal Report:
I've tried a prototype with Crystal Report, it was fine, it's very easy to configure and format the report layout.
But, when I really want to try this in my application, I was prompted to enter the connection information. Well, I have no idea what XML file I should key in for the File Path.
Perhaps a XML format for the Class?
Well, I was just stuck here, and don't know how to proceed further.

Embedded Report:
As for the embedded report, I'm having problem too.
I have this error: "A data source instance has not been supplied for the data source..."
Well, I have no idea what to do right now.

Perhaps just take a break, and continue later.

Friday, May 11, 2007

Split string

The IC Number format is "770131-08-1234", and I need to split the text into 3 different sections, to display on the screen.

There are many times we need to split a string with a delimiter.
The Split() function can help to deal with these cases easily.
Note that the delimiter is a character.

Example 1: Split with one delimiter
string stringToSplit = "770131-08-1234";
string[] splitStrings = stringToSplit.Split('-');

splitStrings[0] will be "770131".
splitStrings[1] will be "08".
splitStrings[2] will be "1234".

Example 2: Split with more than one delimiter
string stringToSplit = "770131;08-1234";
string[] splitStrings = stringToSplit.Split('-',';');

splitStrings[0] will be "770131".
splitStrings[1] will be "08".
splitStrings[2] will be "1234".

Example 3: Split without delimiter
Spaces will be treated as delimiter.
string stringToSplit = "770131 08 1234";
string[] splitStrings = stringToSplit.Split();

splitStrings[0] will be "770131".
splitStrings[1] will be "08".
splitStrings[2] will be "1234".

I've prepared a simple demonstration --> Split String
It's relatively slow compared to working on my own laptop.
Perhaps you can also download the source code here.
SplitString demo (SplitString.zip : 4.5KB)

Display image in GridView according to the value

I have a boolean field in the dataset called "isImportant".
I want to bind this field to the GridView, so that if the value is true, it'll show a red flag.
Display Image in GridView

I actually searched for quite sometime, and at last found that it's actually very simple to do that.
1. Create a Template Field for the column.
2. Add a Image control in the ItemTemplate.
3. Set the ImageUrl for the Image.
4. Right click on the Image control and select "Edit DataBindings....".
5. You'll see the "DataBinding" dialog box.
Edit databinding
(Click to see the larger image)
5. Select the "Visible" property in the "Bindable properties" list.
6. For "Custom binding" section, type: Bind("IsImportant").
7. It's done.
When the "IsImportant" value is true, the image will be shown.
Otherwise, the image will be invisible.

If you know there is any simpler or better way to do this, please let me know. ^_^

Monday, May 7, 2007

Format DateTime in GridView

Well, this could be very simple, but it could be hard if you don't know the key.

Just click on the arrow icon located at the top right corner of the GridView, and select "Edit columns...".
The following dialog box will be displayed.
Formatting DateTime in GridView
(Click on the above image to view the larger image)

Select the DateTime field.
Then change the value for the following properties:
* DataFormatString: {0:dd/MM/yyyy}
* HtmlEncode: False

You'll get the following DateTime display in your Gridview.
GridView DateTime display