Friday, September 4, 2009

Advanced CheckboxList With images

While implementing flights page i came across very interesting Challenge to Dynamically display Airlines list with checkbox .
Asp .net provides Checkboxlist control which do this very efficiently .
But it does not provide functionality to display images as a text .
Here we go how to implement Custom CheckboxList which can accomodate differnt differnt needs
Step 1 :
override the checkboxlists RenderItem method as follows .

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.IO;
using System.Security.Permissions;


namespace Trip.App
{
[AspNetHostingPermission(SecurityAction.Demand, Level =AspNetHostingPermissionLevel.Minimal)]
public class AdvancedCheckBoxList:CheckBoxList
{
//this method constructs customised HTML as per the need .
protected override void RenderItem(ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
{
Image img = new Image();
String imgDetails = Items[repeatIndex].Text;
String[] imgInfo = imgDetails.Split('');
img.ImageUrl = imgInfo[0];
img.ToolTip = imgInfo[1];
Items[repeatIndex].Text = "";
//Displays Checkbox
base.RenderItem(itemType, repeatIndex, repeatInfo, writer);
img.RenderControl(writer);
writer.Write("
");
}
}
}
here i just constructed the HTMl i need to render .

Step 2 :
Add tag prefix and add the Custom Checkboxlist on u r page

<%@ Register TagPrefix="AdvCbl" Namespace="Trip.App" Assembly="web" %>
RepeatDirection="vertical" RepeatLayout="Table"
CellSpacing="3" CellPadding="3" CssClass="ctrl" BorderWidth="0" />

Step 3:
Page Load Code

protected void PopulateAirlinesWithBestPrice(List Airlines)
{
foreach (AirVendor airLinesObj in Airlines)
{
ListItem item = new ListItem();
item.Value = airLinesObj.Code.ToString();
item.Text = "../images/air/24x24/" + airLinesObj.Code.ToString() + ".gif" + airLinesObj.Name.ToString();
//Attributes["URL"]
item.Selected = true;
// item.Attributes["ToolTip"] = airLinesObj.Name.ToString();
cblAirlinesFilter.Items.Add(item);
}
cblAirlinesFilter.RepeatColumns = 1;
cblAirlinesFilter.RepeatDirection = RepeatDirection.Vertical;
cblAirlinesFilter.DataBind();
}

Tuesday, March 24, 2009

Ups and Downs

Suddenly started feeling so lonely ,so boared .I am confused is it the same rashmi who is always full of enthusiasam ,ready to accept life as it is and always hopeing for the best .
why this happens that for no reasons we suddenly become upset ?
why the world around us looks so much boaring .
On the otherhand some time there is one more interesting phase in life where without reason we feel good about everything . "Kuch toh hua hai kuch ho gaya hai "
life is full of mysteries

Sunday, October 19, 2008

WHEN U DESIRE SOMETHING FROM HEART WHOLE UNIVERSE CONSPIRES U IN ACHIEVING THE SUCCESS

WELL,
I ALWAYS BELIEVE IN TAKING UP NEW CHALLENGES FOR THE BETTER FUTURE AND SUCCESS.
the important thing i learned in last 3 months after quitting my current job just for the work satisfaction reason is that if u want challenging life then u need to have courage for facing failures (learning opportunity) coming your way and converting it to a success.
well, i believe if u really desire something(good thoughts no terrorism) from the bottom of heart whole universe conspires in achieving the success. well i have one strong desire right at the moment to become a successful solution architect in near future and i got an opportunity to prove my talents if i will be able to do that then i am sure i will be unstoppable from achieving my goal. will keep posting what will be the next .
right now i just think of 100% attempt from my side .

Friday, October 17, 2008

Opportunities plays great role in life

Hi ,
this is my first post on my own blog .i had a dream of having my own blog writing creative things happening around and be in touch with current technology trends ,but with day to day routine dream only remained dream till today . Today is a special day and all thanks to the Directi , i came across opening at directi and to my surprise there was a criteria that the candidate should be a good blogger (required skills )that's truly innovative .
After knowing the wonderful achievements by young entrepreneurs like bhavin & divyank i decided to create a blog today itself .