Archive for November, 2009

Calendar Extender and Textbox set to Read only in – C#

November 30, 2009 Leave a comment

Lets say we have a textbox control and calendar extender associated with it.Now if we want to set the textbox to read only mode, we set Readonly = true

But there is a problem with it.

Setting the readonly atrribute as stated here will not cause any serverside processing to occur. If you need the value in the textbox to be available serverside then use the attribute


rather than read only. This only works for IE browsers however.

so the code becomes.

<asp:TextBox ID=”txtDate” contentEditable=”false” runat=”server” CssClass=”txtcss”></asp:TextBox>&nbsp;
<asp:Image ID=”imgCal” runat=”server” ImageUrl=”~/img/calendar.gif” />
<cc1:CalendarExtender ID=”CalExtDate” runat=”server”  PopupButtonID=”imgCal”
PopupPosition=”BottomLeft” Format=”dd/MM/yyyy”    TargetControlID=”txtDate”>

Change Background color of last updated record in Gridview in

November 24, 2009 Leave a comment

Here in this post,i m gonna show how to change background color of last updated record in gridview.

Normally what happens after we have updated any record we redirect or bind grid again, so grid comes to first page and we dont know which record we updated if there are many records.

Lets say we have a gridview with 15 records and paging of 5.

If we go to page 2 and click on “edit” link of 8th record in gridview and update that record, now after that we have to change the background row color of 8th record in gridview on 2nd page. So for that we have to maintain the primary key of that record and page index in session whenever we call edit method.

Now on gridview row databound you have to do this code:

protected void Gv_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
int id = Convert.ToInt32(Gv.DataKeys[e.Row.RowIndex].Value.ToString());
if (id == Convert.ToInt32(Session[“pkid”]))
e.Row.CssClass = “UpdateRecordCss”;



also after binding grid you have to maintain page index

GvMake.PageIndex = Convert.ToInt32(Session[“pgindex”]);

Css for that is as follows:

.UpdateRecordCss td

background-color: Green;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=’#B09900′,EndColorStr=’#FFF192′); /*FILTER: progid:DXImageTransform.Microsoft.Alpha( style=1,opacity=25,finishOpacity=100,startX=0,finishX=100,startY=100,finishY=0);*/

Using Enum in Gridview in

November 17, 2009 Leave a comment

Lets say we want to bind a gridview with table having Fields

1) Customer Name

2) Category

Now in the database Category field is stored as tiny int like 0 or 1 or 2

0 Stands for Sales

1 Stands for Marketing

2 Stands for Production

So, now when the gridview is bind, it will display o,1 values. instead of this we want their respective category name to be displayed.

For this we define a ENUM as follows

public enum Category

Sales= 0,

Marketing= 1,

Production= 2

Now in the gridview source in the template field write this code.

<asp:TemplateField HeaderText=”Category”>
<%# Enum.GetName(typeof(GlobalLibrary.Constants.Category),Convert.ToInt32(Eval(“Category”))) %>

Here in Globallibray.Constants is my project with Constants Class.. you can replace it with yours..