Facts
I have a gridview in wich the user will do the editing. The GridView has a CommandField with the ButtonType set to Image
The problem
I want the images to be in the Theme Folder, but the CommandField doesn't seem to support this behaviour.
The solution
After searching the web, I realized that other developers had the same problem. Here is my solution to the problem
I've created a class named CommandField that inherits from System.Web.UI.WebControls.CommandField.
In that class I overrided the method Initialize to look like this:
public override bool
Initialize(bool sortingEnabled, System.Web.UI.Control control)
{
if (EditImageUrl.StartsWith("^"))
base.EditImageUrl = "~/App_Themes/"
+ control.Page.Theme + EditImageUrl.Substring(1);
if (CancelImageUrl.StartsWith("^"))
base.CancelImageUrl = "~/App_Themes/"
+ control.Page.Theme + CancelImageUrl.Substring(1);
if (UpdateImageUrl.StartsWith("^"))
base.UpdateImageUrl = "~/App_Themes/"
+ control.Page.Theme + UpdateImageUrl.Substring(1);
if (DeleteImageUrl.StartsWith("^"))
base.DeleteImageUrl = "~/App_Themes/"
+ control.Page.Theme + DeleteImageUrl.Substring(1);
return base.Initialize(sortingEnabled,
control);
}
In the GridView you have to specify the URLs like this:
<skt:CommandField ButtonType="Image" ShowEditButton="true" ShowCancelButton="true" ShowDeleteButton="true" EditImageUrl="^/Images/GridViewEdit.gif" UpdateImageUrl="^/Images/GridViewUpdate.gif" CancelImageUrl="^/Images/GridViewCancel.gif" DeleteImageUrl="^/Images/GridViewDelete.gif" />
The basic idea is that the ^ character represents the Current Theme in the App_Themes folder. Notice that I used <skt:CommandField and not <asp:CommandField. This is because <skt: is mapped to the namespace where I created my class CommandField.
If you have another solution feel free to comment.
Posted
4-8-2009 15:31
por
Daniel Vinagre