Monday, October 4, 2010

Grid view design


Grid view Row Command

#region GridViewUser_RowCommand
protected void GridViewUser_RowCommand(object sender, GridViewCommandEventArgs e)
{

if (e.CommandName == "DeleteCommand")
{
deleteRecords();
}

if (e.CommandName == "SaveCommand")
{


ImageButton imgBtn = (ImageButton)GridViewUser.Rows[GridViewUser.EditIndex].FindControl("imgSave");
int Indx = 0;
try
{
if (imgBtn.CommandArgument != "")
Indx = int.Parse(imgBtn.CommandArgument);
else
Indx = GridViewUser.EditIndex;

}
catch (Exception)
{
Indx = GridViewUser.EditIndex;
}

//int rowId = Convert.ToInt32(e.CommandArgument);
string procedure = "SP_UPDATE_USERDATA_BY_USERID";

TextBox txtUserName = ((TextBox)GridViewUser.Rows[Indx].FindControl("txtUserName"));
TextBox txtPassword = ((TextBox)GridViewUser.Rows[Indx].FindControl("txtPassword"));
Label lblUserID1 = ((Label)GridViewUser.Rows[Indx].FindControl("lblUserID1"));

int result = userEntity.UpdateUserData(Convert.ToInt32(lblUserID1.Text), txtUserName.Text, txtPassword.Text, procedure);

if (result > 0)
{
lblMessage.Text = "Records updated successfully";
lblMessage.ForeColor = Color.Green;
GridViewUser.EditIndex = -1;
BindGrid();

}
else
{
lblMessage.Text = "Records already Exist";
lblMessage.ForeColor = Color.Red;
}
}

if (e.CommandName == "EditCommand")
{
GridViewUser.EditIndex = Convert.ToInt32(e.CommandArgument);
BindGrid();

}
}

#endregion

Grid view Row Command

#region GridViewUser_RowCommand
protected void GridViewUser_RowCommand(object sender, GridViewCommandEventArgs e)
{

if (e.CommandName == "DeleteCommand")
{
deleteRecords();
}

if (e.CommandName == "SaveCommand")
{


ImageButton imgBtn = (ImageButton)GridViewUser.Rows[GridViewUser.EditIndex].FindControl("imgSave");
int Indx = 0;
try
{
if (imgBtn.CommandArgument != "")
Indx = int.Parse(imgBtn.CommandArgument);
else
Indx = GridViewUser.EditIndex;

}
catch (Exception)
{
Indx = GridViewUser.EditIndex;
}

//int rowId = Convert.ToInt32(e.CommandArgument);
string procedure = "SP_UPDATE_USERDATA_BY_USERID";

TextBox txtUserName = ((TextBox)GridViewUser.Rows[Indx].FindControl("txtUserName"));
TextBox txtPassword = ((TextBox)GridViewUser.Rows[Indx].FindControl("txtPassword"));
Label lblUserID1 = ((Label)GridViewUser.Rows[Indx].FindControl("lblUserID1"));

int result = userEntity.UpdateUserData(Convert.ToInt32(lblUserID1.Text), txtUserName.Text, txtPassword.Text, procedure);

if (result > 0)
{
lblMessage.Text = "Records updated successfully";
lblMessage.ForeColor = Color.Green;
GridViewUser.EditIndex = -1;
BindGrid();

}
else
{
lblMessage.Text = "Records already Exist";
lblMessage.ForeColor = Color.Red;
}
}

if (e.CommandName == "EditCommand")
{
GridViewUser.EditIndex = Convert.ToInt32(e.CommandArgument);
BindGrid();

}
}

#endregion

Design view Grid

Width="100%" CellPadding="0" CellSpacing="1" BorderColor="#85888A" BorderWidth="1px"
OnRowCommand="GridViewUser_RowCommand" OnRowDataBound="GridViewUser_RowDataBound" EmptyDataText="No Record Found" HorizontalAlign="Left">





OnClientClick="Delete();" />


























'







'>



find control in Gridview Row DataBound

#region GridViewUser_RowDataBound

protected void GridViewUser_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
try
{
((ImageButton)e.Row.FindControl("imgEdit")).CommandArgument = e.Row.RowIndex.ToString();


}
catch { }
}
}

#endregion

Delete record with checkbox

private void deleteRecords()
{
bool ischecked = false;
for (int i = 0; i < GridViewUser.Rows.Count; i++)
{
CheckBox chkBox = ((CheckBox)GridViewUser.Rows[i].FindControl("chkBox"));

if (chkBox.Checked == true)
{
ischecked = true;
Label lblUserID = ((Label)GridViewUser.Rows[i].FindControl("lblUserID"));

string procedurename = "SP_DELETE_USERDATA_BY_USERID";

int result = userEntity.deleteUserRecords(Convert.ToInt32(lblUserID.Text), procedurename);

if (result > 0)
{
lblMessage.Text = "Records deleted successfully!";
lblMessage.ForeColor = Color.Green;
BindGrid();
}

else
{

lblMessage.Text = "Error while deleting records";
lblMessage.ForeColor = Color.Red;
}


}

}
if (!ischecked)
{
lblMessage.Text = "Please select at least one records";
lblMessage.ForeColor = Color.Red;
}
}

Pass Storeprocedure how

#region btnSubmit_Click

protected void btnSubmit_Click(object sender, EventArgs e)
{
string userName = txtUserName.Text.Trim();
string password = txtPassword.Text.Trim();

string storeProcedure = "SP_FETCH_USER_DATA";
DataTable resultDatatable = userEntity.fetchUserData(userName,password,storeProcedure);
if(resultDatatable!=null && resultDatatable.Rows.Count>0)
{
Response.Redirect("~/WelCome.aspx");
}

else
private void BindGrid()
{
string procedureName = "SP_FETCH_ALL_USERDATA";
DataTable resultDatatable = userEntity.FetchAllUserData(procedureName);
if (resultDatatable != null && resultDatatable.Rows.Count > 0)
{
GridViewUser.DataSource = resultDatatable;
GridViewUser.DataBind();

}

else
{
GridViewUser.DataBind();
}



}
{
Label1.Text = "Invalid Username and Password";
Label1.ForeColor = Color.Red;
}




}

#endregion

Connection Class

#region userConnectionString
public static string userConnectionString
{

get
{
return (ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

}


}
#endregion

#region ConnectionProcedure

public static SqlCommand ConnectionProcedure()
{

SqlConnection cn = new SqlConnection(UserEntity.userConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cn.Open();
cmd.CommandType = CommandType.StoredProcedure;
return (cmd);



}

#endregion

#region FetchUserData
public DataTable fetchUserData(string userEmail, string userPassword, string Storeprocedurename)
{
try
{
SqlCommand cmd = UserEntity.ConnectionProcedure();
cmd.CommandText = Storeprocedurename;
cmd.Parameters.AddWithValue("@USER_EMAIL", userEmail);
cmd.Parameters.AddWithValue("@USER_PASSWORD", userPassword);

//SqlParameter addoutprm = new SqlParameter("@COOUT", "1");
//addoutprm.Direction = ParameterDirection.Output;
//cmd.Parameters.Add(addoutprm);

SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);


if (dt != null && dt.Rows.Count > 0)
{
return dt;
}
else
{
return null;
}

}
catch (Exception ex)
{
return null;
}
}
#endregion

#region deleteUserRecords

public int deleteUserRecords(int userId, string storeProcedure)
{
int result = 0;
try
{
SqlCommand cmd = UserEntity.ConnectionProcedure();
cmd.CommandText = storeProcedure;
cmd.Parameters.AddWithValue("@USER_ID", userId);
SqlParameter prm = new SqlParameter("@POUTRESULT", 0);
prm.Direction = ParameterDirection.Output;
cmd.Parameters.Add(prm);
result = cmd.ExecuteNonQuery();

int r = Convert.ToInt32(prm.Value);

if (result > 0)
{
return r;
}
else
{
return 0;
}
}
catch (Exception ex)
{
return 0;

}



}


#endregion

#region UpdateUserData

public int UpdateUserData(int userId, string userName, string passWord, string procedureName)
{
try
{
int result = 0;
SqlCommand cmd = UserEntity.ConnectionProcedure();
cmd.CommandText = procedureName;
cmd.Parameters.AddWithValue("@USER_ID", userId);
cmd.Parameters.AddWithValue("@USER_NAME", userName);
cmd.Parameters.AddWithValue("@USER_PASSWORD", passWord);
SqlParameter prm = new SqlParameter("@POUTRESUT", 9);
prm.Direction = ParameterDirection.Output;
cmd.Parameters.Add(prm);
result = cmd.ExecuteNonQuery();

if (result > 0)
{
return result;
}
else
{
return 0;
}

}
catch (Exception ex)
{
return 0;

}


}
#endregion

Friday, August 27, 2010

aspxtutorial

Asp.net tutorial and discussion
http://www.aspxtutorial.com/

A Blog by Dhananjay Kumar
http://dhananjaykumar.net/
Good Tutorials

Thursday, August 26, 2010

Entity Framework 4.0- Bind Stored Procedure with Result Entity class

Titele : Entity Framework 4.0- Bind Stored Procedure with Result Entity class

Description : Microsoft Entity Framework version 4.0 is a brand new ORM(Object Relational Mapper) from Microsoft. It’s provides now some new features which are not there in the earlier version of Entity framework. Let’s walk through a simple example of a new features which will create a new Entity class based on stored procedure result. We will use same table for this example for which they have used earlier for Linq Binding with Custom Entity.

Link: http://beyondrelational.com/blogs/jalpesh/archive/2010/08/18/entity-framework-4-0-bind-stored-procedure-with-result-entity-class.aspx

Monday, August 16, 2010

Get GridView rowcount and cell and row text Javascript


var _gridView = document.getElementById('ctl00_Body__quickEntryList_QuickEntryList');

var _rowcount = _gridView.rows.length;

for (i = 1; i <>
var _cell = _gridView.rows[i].cells;
var _HTML = _cell[0].children[0].value;

Friday, July 2, 2010

File Upload & Compression in ASP.Net

http://www.beansoftware.com/asp.net-tutorials/file-upload-compression.aspx

http://forums.asp.net/t/1086292.aspx

http://geekswithblogs.net/twickers/archive/2005/11/08/59420.aspx

Tuesday, June 29, 2010

Adding Dynamic Rows in GridView with TextBoxes

To get started, let’s grab a GridView control from the Visual Studio Toolbox and put it in the WebForm. The mark up would look something like this:

<asp:gridview ID="Gridview1" runat="server" ShowFooter="true" AutoGenerateColumns="false">

<Columns>

<asp:BoundField DataField="RowNumber" HeaderText="Row Number" />

<asp:TemplateField HeaderText="Header 1">

<ItemTemplate>

<asp:TextBox ID="TextBox1" runat="server">asp:TextBox>

ItemTemplate>

asp:TemplateField>

<asp:TemplateField HeaderText="Header 2">

<ItemTemplate>

<asp:TextBox ID="TextBox2" runat="server">asp:TextBox>

ItemTemplate>

asp:TemplateField>

<asp:TemplateField HeaderText="Header 3">

<ItemTemplate>

<asp:TextBox ID="TextBox3" runat="server">asp:TextBox>

ItemTemplate>

<FooterStyle HorizontalAlign="Right" />

<FooterTemplate>

<asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" />

FooterTemplate>

asp:TemplateField>

Columns>

asp:gridview>

Since this demo is intended to generate rows of TextBoxes in GridView, then we set up some TemplateFields columns so that GridView will automatically generates TextBoxes when a new row is being added.

As you can see I have set up a BoundField Column for displaying the RowNumber and sep up three TemplateField Columns in the Grid and added each columns a TextBox Control. You would also noticed that I have added a Button Control under the FooterTemplate at the last column in the GridView.

Note: Since we are added a Control in the GridView footer, then be sure to set ShowFooter to TRUE in the GridView.

Now let’s switch to the Code behind part of the webform.

As you may know, the GridView control will not show in the page once there is no data associated on it. So the first thing we need here is to set an initial data in the GridView Control. To do this, we can use a DataTable for binding our GridView.

Here’s the code block below:

private void SetInitialRow()

{

DataTable dt = new DataTable();

DataRow dr = null;

dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));

dt.Columns.Add(new DataColumn("Column1", typeof(string)));

dt.Columns.Add(new DataColumn("Column2", typeof(string)));

dt.Columns.Add(new DataColumn("Column3", typeof(string)));

dr = dt.NewRow();

dr["RowNumber"] = 1;

dr["Column1"] = string.Empty;

dr["Column2"] = string.Empty;

dr["Column3"] = string.Empty;

dt.Rows.Add(dr);

//dr = dt.NewRow();

//Store the DataTable in ViewState

ViewState["CurrentTable"] = dt;

Gridview1.DataSource = dt;

Gridview1.DataBind();

}

As you can see, we defined four Columns in the DataTable called RowNumber, Column1, Column2 and Column3. The RowNumber column will serve as the key for generating the rows in the GridView. Noticed that for Columns 1,2 and 3, I assigned an empty value for that columns since the GridView will be generated for the first time. You also noticed that I store the DataTable in ViewState so that we can reference the current data associated within the DataTable when it postbacks.

Now lets call the method above in Page_Load event:

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

SetInitialRow();

}

}

Running the codes above will give us this output below:

Now let’s create the method for generating the rows when clicking the Button. Here are the code blocks below:

private void AddNewRowToGrid()

{

int rowIndex =0;

if (ViewState["CurrentTable"] != null)

{

DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];

DataRow drCurrentRow = null;

if (dtCurrentTable.Rows.Count > 0)

{

for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)

{

//extract the TextBox values

TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");

TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");

TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("TextBox3");

drCurrentRow = dtCurrentTable.NewRow();

drCurrentRow["RowNumber"] = i + 1;

drCurrentRow["Column1"] = box1.Text;

drCurrentRow["Column2"] = box2.Text;

drCurrentRow["Column3"] = box3.Text;

rowIndex++;

}

//add new row to DataTable

dtCurrentTable.Rows.Add(drCurrentRow);

//Store the current data to ViewState

ViewState["CurrentTable"] = dtCurrentTable;

//Rebind the Grid with the current data

Gridview1.DataSource = dtCurrentTable;

Gridview1.DataBind();

}

}

else

{

Response.Write("ViewState is null");

}

//Set Previous Data on Postbacks

SetPreviousData();

}

As a summary, the code above gets the previous data stored from the viewstate and set the data stored from it into a DataTable so that we can add a new row based from the value entered from the TextBox.

You will also noticed that we call the method SetPreviousData() at the bottom part of the codes above. Now where is that method? Below are the code blocks for that method:

private void SetPreviousData()

{

int rowIndex = 0;

if (ViewState["CurrentTable"] != null)

{

DataTable dt = (DataTable)ViewState["CurrentTable"];

if (dt.Rows.Count > 0)

{

for (int i = 1; i <>

{

TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");

TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");

TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("TextBox3");

box1.Text = dt.Rows[i]["Column1"].ToString();

box2.Text = dt.Rows[i]["Column2"].ToString();

box3.Text = dt.Rows[i]["Column3"].ToString();

rowIndex++;

}

}

}

}

Now, since the methods are all set then we can call this at Button Click event of the Button.

protected void ButtonAdd_Click(object sender, EventArgs e)

{

AddNewRowToGrid();

}

As you can see the code above is very straight forward and self explanatory. Running the code above will give us this output below:

That’s it! Hope you will find this example useful!


Tuesday, June 22, 2010

Paging via a SQL Server Stored Procedure

The third and final approach involves a stored procedure. This is the most efficient approach because, unlike ADO and getrows which both return the entire set of records to the Web server, the stored procedure returns only the records that are needed for the current page.

Once again, the paging algorithm is roughly the same as ADO, but here the current page and the page size are passed into the stored procedure as input parameters. The stored procedure then selects the set of records needed for the current page by setting up a temporary table with an identity field and using the identity field to determine which records should be returned, given the current page and page size.

CREATE PROCEDURE "sprocInformationTechnologyProjects"  @Page int, @Size int  AS  DECLARE @Start int, @End int  BEGIN TRANSACTION GetDataSet  SET @Start = (((@Page - 1) * @Size) + 1) IF @@ERROR <> 0  GOTO ErrorHandler  SET @End = (@Start + @Size - 1) IF @@ERROR <> 0  GOTO ErrorHandler  CREATE TABLE #TemporaryTable (  Row int IDENTITY(1,1) PRIMARY KEY,  Project varchar(100),  Buyer int,  Bidder int,  AverageBid money ) IF @@ERROR <> 0  GOTO ErrorHandler  INSERT INTO #TemporaryTable SELECT ... // Any kind of select statement is possible with however many joins //  as long as the data selected can fit into the temporary table. IF @@ERROR <> 0  GOTO ErrorHandler  SELECT Project, Buyer, Bidder, AverageBid FROM #TemporaryTable WHERE (Row >= @Start) AND (Row <= @End) IF @@ERROR <> 0  GOTO ErrorHandler  DROP TABLE #TemporaryTable  COMMIT TRANSACTION GetDataSet RETURN 0  ErrorHandler: ROLLBACK TRANSACTION GetDataSet RETURN @@ERROR

Reference : http://www.15seconds.com/issue/010308.htm
 http://blog.sqlauthority.com/2007/06/11/sql-server-2005-t-sql-paging-query-technique-comparison-over-and-row_number-cte-vs-derived-table/
 


How do I find a stored procedure containing ?

SELECT OBJECT_NAME(id)
FROM syscomments
WHERE [text] LIKE '%nilesh%'
AND OBJECTPROPERTY(id, 'IsProcedure') = 1
GROUP BY OBJECT_NAME(id)



Sunday, June 13, 2010

Friday, June 11, 2010

Good Design Templates

http://naldzgraphics.net/inspirations/web-design-inspiration-55-beautifully-made-single-page-designs/comment-page-1/#comment-64712

http://sixrevisions.com/design-showcase-inspiration/35-beautiful-water-themed-web-designs-for-inspiration/

http://www.thecoronabeach.com/


Friday, June 4, 2010

SQL SERVER – Count Duplicate Records – Rows

SELECT YourColumn, COUNT(*) TotalCount
FROM YourTable
GROUP BY YourColumn
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC

Wednesday, April 28, 2010

15 Tools for Testing your Website

http://www.graphicrating.com/2009/08/11/15-tools-for-testing-your-website

Description: Check out this tools which shows every person importance of in one websites or project, in this 15 tools check the last one which check the whole page.

vertical jquery

Some Good Jquery

http://malsup.com/jquery/cycle/

10+ jQuery photo gallery and slider plugins

http://twitter.com/mateuscneves/status/5647525040


http://www.hesido.com/web.php?page=customscrollbar
Description : A Cross Browser* and Standards Compliant Custom ScrollBar Script by Hesido

http://www.hesido.com/

Online Editor for the Web (JavaScript, MooTools, jQuery, Prototype, YUI, Glow and Dojo, HTML, CSS)

http://jsfiddle.net/F3qsp/

jQuery - Horizontal Accordion

Description : 1. handle aligned to the left; animation is opening and closing content at the same time; event trigger is mouse

Link: http://www.portalzine.de/Horizontal_Accordion_Plugin_2/index.html


http://blog.evaria.com/wp-content/themes/blogvaria/jquery/index.php


http://thedesigned.com/2009/09/25/10-examples-of-impressive-jquery-accordions/


http://www.webdesign.org/html-and-css/tutorials/jquery-examples-horizontal-accordion.15528.html

SQL SERVER – 2008 – Configure Database Mail – Send Email From SQL Database

Title : SQL SERVER – 2008 – Configure Database Mail – Send Email From SQL Database

http://blog.sqlauthority.com/2008/08/23/sql-server-2008-configure-database-mail-send-email-from-sql-database/

Desc :Today in this article I would discuss about the Database Mail which is used to send the Email using SQL Server.

Net-Snippets

http://dotnet-snippets.com/dns/default.aspx

Description : Different types of snippest for .net here ex :Pay Pal IPN,Get all Outlook Contacts,Full Screen….

Using Tiny MCE Rich TextBox in ASP.Net

http://www.aspsnippets.com/Articles/Using-Tiny-MCE-Rich-TextBox-in-ASP.Net.aspx

SQL Server Date Formats

http://www.sql-server-helper.com/tips/date-formats.aspx