Wednesday, July 15, 2009
Log File
Tuesday, July 14, 2009
Showing Total in GridView
Sunday, July 12, 2009
Calculations in Gridview
- <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
- DataKeyNames="ItemID" DataSourceID="sqlDataSource1"
- onrowdatabound="GridView1_RowDataBound">
- <Columns>
- <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
- <asp:BoundField DataField="ItemID" HeaderText="ItemID" InsertVisible="False"
- ReadOnly="True" SortExpression="ItemID" />
- <asp:TemplateField HeaderText="quantity" SortExpression="quantity">
- <EditItemTemplate>
- <asp:TextBox ID="txtQuantity" runat="server" Text='<%# Bind("quantity") %>'></asp:TextBox>
- </EditItemTemplate>
- <ItemTemplate>
- <asp:Label ID="Label1" runat="server" Text='<%# Bind("quantity") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField HeaderText="price" SortExpression="price">
- <EditItemTemplate>
- <asp:TextBox ID="txtPrice" runat="server" Text='<%# Bind("price") %>'></asp:TextBox>
- </EditItemTemplate>
- <ItemTemplate>
- <asp:Label ID="Label2" runat="server" Text='<%# Bind("price") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField HeaderText="amount" SortExpression="amount">
- <EditItemTemplate>
- <asp:TextBox ID="txtAmount" runat="server" Text='<%# Bind("amount") %>'></asp:TextBox>
- </EditItemTemplate>
- <ItemTemplate>
- <asp:Label ID="Label3" runat="server" Text='<%# Bind("amount") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- </Columns>
- </asp:GridView>
and the RowDataBound event is
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- TextBox txtQuantity = (TextBox)e.Row.FindControl("txtQuantity");
- TextBox txtPrice = (TextBox)e.Row.FindControl("txtPrice");
- TextBox txtAmount = (TextBox)e.Row.FindControl("txtAmount");
- if (txtQuantity != null)
- {
- txtQuantity.Attributes.Add("onkeyup", "CalcAmount('" + txtQuantity.ClientID + "','" + txtPrice.ClientID + "','" + txtAmount.ClientID + "')");
- txtPrice.Attributes.Add("onkeyup", "CalcAmount('" + txtQuantity.ClientID + "','" + txtPrice.ClientID + "','" + txtAmount.ClientID + "')");
- }
- }
- }
and the javascript method will look like this
- <script type="text/javascript">
- function CalcAmount(quantity, price, amount) {
- document.getElementById(amount).value = parseFloat(document.getElementById(quantity).value) * parseFloat(document.getElementById(price).value);
- }
- </script>
This way when the values are changed in the quantity and price textboxes,
the corresponding amount textbox updates automatically.
Thursday, July 9, 2009
icon on the tab of a website in a web broswer
how to make an icon on the tab of a website in a web broswer |
Create an .ico file and add in Header section <link rel="shortcut icon" href="favicon.ico"> You can create an .ico image using this link http://www.chami.com/html-kit/services/favicon/ |
Getting week of the month from a Date
Getting week of the month from a DateTime variable |
// ---- GetWeekOfMonth --------------------------- // // Assuming Sunday starts a new week, get the ordinal // week a date is in...of the date's month // using Microsoft.VisualBasic; int GetWeekOfMonth(DateTime Date) { long Week; // get first day of month DateTime BaseDate = new DateTime(Date.Year, Date.Month, 1); // get difference, in weeks, between the date and first day of month Week = DateAndTime.DateDiff(DateInterval.WeekOfYear, BaseDate, Date, Microsoft.VisualBasic.FirstDayOfWeek.Sunday, FirstWeekOfYear.Jan1); // want it one, not zero based return (int)Week + 1; } // test it protected void Button1_Click(object sender, EventArgs e) { DateTime Date = new DateTime(2007, 3, 1); while (Date.Month == 3) { int Week = GetWeekOfMonth(Date); Response.Write(String.Format("{0:d} : {1} <BR>", Date, Week)); Date = Date.AddDays(1); } } |
RequiredFiledValidator For CheckBoxList
RequiredFiledValidator For CheckBoxList |
function checkTemp(sender,args) { for(var i=0;i<=document.getElementById("CheckBoxList1").firstChild.children.length-1;i++) { if(document.getElementById("CheckBoxList1").firstChild.children(i).cells(0).children(0).checked)=='true' args.IsValid=true return } args.IsValid=false } <asp:CustomValidator id="valcheckBoxTemp" runat="server" ClientValidationFunction="checkTemp" ErrorMessage="This is required control "></asp:CustomValidator> |
Disable Copy Command
Disable Copy Command |
oncopy="return false;" onpaste="return false;" oncut="return false;" |
Alternate image when the orginal image is missing
How to provide an alternate image when the orginal image is missing? |
<img border=0 src='<%# (Eval("Image").ToString() != null) ? "http://www.mynewsite.com/Images/thumb/" + Eval("Image") : "path_of_dummy_image" %>' /> |
Finding Particular Controls in Page
Finding Particular Controls in Page |
private Control FindNestedControl(Control parent, string controlid) { Control c = parent.FindControl(controlid); if (c != null) return c; else { foreach (Control child in parent.Controls) { c = FindNestedControl(child, controlid); if (c != null) return c; } } return null; } Eg :- DropDownList ddlMyList = FindNestedControl(this.Page," ddlMyList") as DropDownList; |
EncryptString & DecryptString
EncryptString |
private string EnryptString (string strEncrypted) {
byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes(strEncrypted); string encryptedConnectionString = Convert.ToBase64String(b); return encryptedConnectionString;
} |
DecryptString |
private string DecryptString (string encrString) {
byte[] b = Convert.FromBase64String(encrString);
string decryptedConnectionString = System.Text.ASCIIEncoding.ASCII.GetString(b);
return decryptedConnectionString;
} |