Wednesday, December 29, 2010

Multiple file upload in asp.net

This code show how to upload multiple file and save to database using asp.net and c#. HttpFileCollection hFileCollection = HttpContext.Current.Request.Files; for (int i = 0; i <= hFileCollection.Count; i++) { HttpPostedFile hPostedFile = hFileCollection[i]; if (hPostedFile.ContentLength > 0) ...

Thursday, October 21, 2010

Rounded off total income

Rounded off total income Int32 roundedAmt; Int32 torounded = Convert.ToInt32(lblTotalIncome.Text); int lastdigit = torounded % 10; if (lastdigit >= 5) { roundedAmt = torounded - lastdigit + 10; } else { roundedAmt = torounded - lastdigit; } lblRoundedOf.Text...

Monday, October 11, 2010

Enable and disable textbox when checked the checkbox

Here code show how enable and disble textbox when user checked the textbox.code disble the row which contain the textbox.you can also take only checkboxto enable and disble not neccessary to disble row.function showHide(){ var chkSignature = document.getElementById('ctl00_ContentPlaceHolder1_tabContainer_pnl_chkSign'); var trsign = document.getElementById('ctl00_ContentPlaceHolder1_tabContainer_pnl_trsign');...

Sunday, October 10, 2010

Bind DropDownList using SqlDataReader

This code pulling out data from a database into a data reader is as follows. protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { bindDDL(); } } Public void bindDDL() { SqlConnection con =new SqlConnection(ConfigurationManager. ConnectionStrings["ConnectionString"].ConnectionString.ToString();)...

Saturday, October 9, 2010

Get duplicated record from sql server table

Here query describes how to find duplicate record from a table in sql serverSELECT User_ID FROM tbl_MemberGROUP BY User_IDHAVING count( * ) > 1Thanks & RegardsSantosh Si...

Friday, October 1, 2010

Refresh the aspx page automatically

This small code refresh the aspx page automatically.Set the time according to your requirment in content="time in sec".<head runat="server"> <title>Untitled Page</title> <meta http-equiv="refresh" content="20" /> </head&...

Thursday, September 30, 2010

select data from one database and insert into another table

insert into tblMonthMstselect * from EMPMain.[dbo].[tblMonthM...

Wednesday, September 29, 2010

Sql Server query Optimization

Optimization in Practice Example 1:I want to retrieve the name and salary of the employees of the R&D department. Original:Query : Select * From EmployeesIn Program : Add a filter on Dept or use command : if Dept = R&D-- Corrected :Select Name, Salary From Employees Where Dept = R&D-- In the corrected version, the DB filters data because...

Tuesday, September 28, 2010

A field or property with the name 'CountryName' was not found on the selected data source.

Sol: In grid you have field but in not tabl...

Saturday, September 18, 2010

GridView with checkbox

This article is very simple.Many time developer need to how develop Gridview with checkbox,so we can select single or multiple record to update.Javascript file <script language="javascript" type="text/javascript"> function SelectAllCheckboxes(spanChk) { var oItem = spanChk.children; var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];...

Friday, September 17, 2010

How to bind GridView with DataSet in ASP.Net and c#

How to bind GridView with DataSet in ASP.Net and c#. In this article I am using ASP.Net GridView control to display data from database.I am using Dataset to fill data and display in Grid. protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { bindGridView(); } }...

Sql Server Interview Questions

1.What are the blocks in stored procedure2. How do you handle exceptions. Give the syntax for it3. What is normalization and types of normalization4. When would you denormalize5. Difference between a query and strored procedure6. What is clustered and non-clustered indexes7. Types of joins8. How do you get all records from 2 tables. Which join do you...

Thursday, September 16, 2010

How to bind data to DropDownList in GridView in ASP.Net and C#

How to bind data to DropDownList in GridView in ASP.Net and C# In this article i am explaining how to bind data to DropDownList inside asp.net GridView control. protected void GridDegree_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DropDownList ddlDegreeType...

Wednesday, September 15, 2010

Create pdf from GridView control in asp.net with c#

Create pdf from GridView using asp.net with c# Here this article show full code for create the pdf file from asp.net GridView. Some time developer need how to do GridView to pdf .Here i have written the method according to my requirement.You can change according to your requirement and use this. public void ConvertDataInPdf(DataTable dtExportInPdf,...

Saturday, September 11, 2010

Bind dropdownlist default value

On RowDataBoundddlCountry.SelectedValue = Ds.Tables[0].Rows[e.Row.RowIndex]["CountryId"].ToString();On SelectedIndexChangedddlRGroup.SelectedValue = Ds.Tables[0].Rows[0]["RatingId"].ToString();if (!Page.IsPostBack)SqlDataReader dr = SqlHelper.ExecuteReader(connectionString, "tblFormula_Select", Convert.ToInt32(ViewState["CKFId"]), "S");ddlTemp.SelectedValue...

Friday, September 10, 2010

Javascript validation for Gridview footer textbox

Javascript validation for Gridview footer textbox Here gridview have footer row that cantain dropdownlist and two textbox.This javascript validate these fields while inserting record in database. function ValidateGrid() { ddlNewCountry = document.getElementById('<%=((DropDownList)gv.FooterRow.FindControl("ddlNewCountry")).ClientID%>');...

Javascript validation for Gridview in edit mode

Javascript validation for Gridview textbox in edit mode Clientside validation for Gridview textboxex while edting record. Here gridview have dropdownlist and two textbox.This javascript clientside code validate these fields while edting record. function ValidateGridEditMode() { var Gid = document.getElementById('ctl00_ContentPlaceHolder1_TabContaner_tabCustomer_gvCustomer').rows.length;...

Gridview control with Edit Delete and Update in ASP.NET using C#

Gridview control with Edit Delete and Update in ASP.NET Gridview Edit/Delete/Update using sqlhelper class and 3 layer architecture. In this article I have tried to make the simple Add , Edit, Update and Delete functions in ASP.Net GridView. Feature of this GridView 1.This example used three tier architecture. 2.Add new record using...

Onclick Gridview Select button fill all the data to textbox.

Onclick Gridview Select button fill all the data to textbox. All the textbox out of gridview. protected void ImgSelect_Click(object sender, ImageClickEventArgs e) { ImageButton aspSender = sender as ImageButton; Label Id = aspSender.FindControl("lblContId") as Label; hdnId.Value = Id.Text; DataSet dsContact...

Monday, September 6, 2010

Join Three Table

How to join three table SELECT e.emp_name, d.DeptNameFROM Emp e INNER JOIN DeptName d ON e.emp_id = d.emp_id JOIN Sal s ON d.dept_id = s.dept_idSELECT a.au_lname, a.au_fname, t.titleFROM authors a INNER JOIN titleauthor ta ON a.au_id = ta.au_id JOIN titles t ON ta.title_id = t.title_idselect r.recipe_name, i.ingredients_list, p.products_listfrom...

How to Store Multiple Value In Session using asp.net c#

How to Store Multiple Value In Session using asp.net c# We can add multiple values by using class entiry or hashtable or arralist: Here a we will use Hashtable for storing multiple value in session Hashtable htEmpInfo = new Hashtable(); htEmpInfo.Add("Name", "Santosh"); htEmpInfo.Add("Designation", "SE"); htEmpInfo.Add("Department",...

OnkeyPress attributes in TextBox using JavaScript

Here code shows how to use onkeypress in TextBox.When user write in textbox a Label show no. of charachter entered in TextBox function valid(txt,maxLen,lbl1) { lbl1.innerText=(txt.value.length+1); if(txt.value.length > (maxLen-1)) { alert("Entered Text reach at its maximum size..!"); return false;...

Sunday, September 5, 2010

Gridview RowCommand

If you hav any button inside Gridview you handle that button under RowCommand like here Gridview have a Insert button inside Grid. protected void gvStuDetails_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("Insert")) { objStuCls.StuId = Convert.ToInt32(((DropDownList)gvStuDetails.FooterRow.FindControl("ddlNewStuId")).SelectedValue);...

Saturday, September 4, 2010

Insert Images to SqlServer in ASP .NET

Here I am explaining how insert images into database using asp.net. protected void Button1_Click(object sender, EventArgs e) { FileUpload fileUpload1 = ((FileUpload)(this.FindControl("fileUpload1"))); if (((fileUpload1.PostedFile == null) || (string.IsNullOrEmpty(fileUpload1.PostedFile.FileName) || (fileUpload1.PostedFile.InputStream...

Friday, September 3, 2010

Validation Groups in ASP.NET 2.0

Validation groups is a new feature of asp.net 2.0.Validation groups help you to group the controls in a page and you can have separate submit buttons for each group.When you submit a group of values from a group,the validation controls pertaining to that group alone is executed.Here is a example how to use validation group.On clicking of Save Button,it...

Thursday, September 2, 2010

asp.net and c# interview Questions and Answers

1. What is a static class? Ans.A static class is a class which can not be instantiated using the ‘new’ keyword. They also only contain static members,are sealed and have a private constructor. Static classes are classes that contain only static members.A static class is basically the same as a non-static class, but there is one difference:...

Wednesday, September 1, 2010

How to add comma in a int or decimal value

This code show how to add comma into int or decimal value.Suppose we have a value 33000 and want to display this 33,000.00. string FirstP = ""; string SecP = ""; string Finalstr = ""; int MyValue = Convert.ToInt32(Projected); string myStr = MyValue.ToString(); ...

ASP.NET Validation Controls with example

Learning Technique for freshers : R3C2 1.RequiredFieldValidation Control 2.RangeValidator Control 3.RegularExpressionValidator Control 4.CompareValidator Control 5.CustomValidator Control Properties of Validation Controls. ControlToValidate - Id of control Which you want to validate. ErrorMessage - Message that...