Thursday 26 December 2013

Move Selected Gridview Rows to Another Gridview in Asp.net

To implement this first we need to write the code in "aspx" page like this::

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Move selected gridview rows to another gridview in Asp.net</title></head>
<body>
<form id="form1" runat="server"><div>
<asp:GridView ID="gvDetails" AutoGenerateColumns="false" CellPadding="5" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="true" OnCheckedChanged="chkSelect_CheckChanged" />
</ItemTemplate>
</asp:TemplateField>

<asp:BoundField HeaderText="UserId" DataField="UserId" />
<asp:BoundField HeaderText="UserName" DataField="UserName" />
<asp:BoundField HeaderText="Education" DataField="Education" />
<asp:BoundField HeaderText="Location" DataField="Location" />
</Columns>
<
HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
</asp:GridView>
<br />
<b>Second Gridview Data</b>
<asp:GridView ID="gvTranferRows" AutoGenerateColumns="false" CellPadding="5" runat="server" EmptyDataText="No Records Found">
<Columns>
<asp:BoundField HeaderText="UserId" DataField="UserId" />
<asp:BoundField HeaderText="UserName" DataField="UserName" />
<asp:BoundField HeaderText="Education" DataField="Education" />
<asp:BoundField HeaderText="Location" DataField="Location" />
</Columns> 
<HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" /></asp:GridView> 
</div></form>
</body>
</html>


========================================================

C# Code

protected void Page_Load(object sender, EventArgs e)

if (!IsPostBack)
{

BindGridview();
BindSecondGrid();
}

}
protected void BindGridview()
{
DataTable dt = new DataTable();
dt.Columns.Add("UserId", typeof(Int32));
dt.Columns.Add("UserName", typeof(string));
dt.Columns.Add("Education", typeof(string));
dt.Columns.Add("Location", typeof(string));
DataRow dtrow = dt.NewRow();    // Create New Row
dtrow[
"UserId"] = 1;   
dtrow["UserName"] = "ChiragPatel";
dtrow[
"Education"] = "M.sc IT";
dtrow[
"Location"] = "Kaalol";
dt.Rows.Add(dtrow);
dtrow = dt.NewRow();

dtrow["UserId"] = 2;
dtrow["UserName"] = "ChinkiPandviya";
dtrow[
"Education"] = "BCA";
dtrow[
"Location"] = "Vadodara";
dt.Rows.Add(dtrow);
dtrow = dt.NewRow();

dtrow["UserId"] = 3;
dtrow["UserName"] = "KinZy";
dtrow[
"Education"] = "BCA";
dtrow[
"Location"] = "Vadodara";

dt.Rows.Add(dtrow);
gvDetails.DataSource = dt;
gvDetails.DataBind();
}
protected void chkSelect_CheckChanged(object sender, EventArgs e)
{
GetSelectedRows();
BindSecondGrid();
}
protected void BindSecondGrid()
{
DataTable dt = (DataTable)ViewState["GetRecords"];
gvTranferRows.DataSource = dt;
gvTranferRows.DataBind();
}
private void GetSelectedRows()
{
DataTable dt;
if (ViewState["GetRecords"] != null)
dt = (DataTable)ViewState[
"GetRecords"];
else
dt = CreateTable();
for (int i = 0; i < gvDetails.Rows.Count; i++)
{
CheckBox chk = (CheckBox)gvDetails.Rows[i].Cells[0].FindControl("chkSelect");
if (chk.Checked)
{
dt = AddGridRow(gvDetails.Rows[i], dt);
}
else
{
dt = RemoveRow(gvDetails.Rows[i], dt);
}
}
ViewState["GetRecords"] = dt;
}
private DataTable CreateTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("UserId");
dt.Columns.Add("UserName");
dt.Columns.Add("Education");
dt.Columns.Add("Location");
dt.AcceptChanges();
return dt;
}
private DataTable AddGridRow(GridViewRow gvRow, DataTable dt)
{
DataRow[] dr = dt.Select("UserId = '" + gvRow.Cells[1].Text + "'");
if (dr.Length <= 0)
{
dt.Rows.Add();
int rowscount = dt.Rows.Count - 1;
dt.Rows[rowscount][
"UserId"] = gvRow.Cells[1].Text;
dt.Rows[rowscount][
"UserName"] = gvRow.Cells[2].Text;
dt.Rows[rowscount][
"Education"] = gvRow.Cells[3].Text;
dt.Rows[rowscount][
"Location"] = gvRow.Cells[4].Text;
dt.AcceptChanges();
}
return dt;
}
private DataTable RemoveRow(GridViewRow gvRow, DataTable dt)
{
DataRow[] dr = dt.Select("UserId = '" + gvRow.Cells[1].Text + "'");
if (dr.Length > 0)
{
dt.Rows.Remove(dr[0]);
dt.AcceptChanges();
}
return dt;
}

====================================================== 

Tuesday 17 December 2013

360 degree spin onMouseover and onMouseout

------------------------------------------------------------------
 <p id="socialicons">
    <a href="http://dot-nettuts.blogspot.in/"><img border="0" src="img/rss.png" /></a>
    <a href="http://dot-nettuts.blogspot.in"><img border="0" src="img/delicious.png" /></a> 
    <a href="http://dot-nettuts.blogspot.in"><img border="0" src="img/facebook.png" /></a>
    <a href="http://dot-nettuts.blogspot.in"><img border="0" src="img/twitter.png" /></a>
    <a href="http://dot-nettuts.blogspot.in"><img border="0" src="img/yahoo.png" /></a>
</p>
<p><b>60 degree spin onMouseover and onMouseout</b></p>
<p id="socialicons2">
   <a href="http://dot-nettuts.blogspot.in"><img border="0" src="img/rss.png" /></a>
   <a href="http://dot-nettuts.blogspot.in"><img border="0" src="img/delicious.png" /></a>
   <a href="http://dot-nettuts.blogspot.in"><img border="0" src="img/facebook.png" /></a>
   <a href="http://dot-nettuts.blogspot.in"><img border="0" src="img/twitter.png" /></a> 
   <a href="http://dot-nettuts.blogspot.in"><img border="0" src="img/yahoo.png" /></a>
</p>
<p><b>-360 degree spin onMouseover ONLY</b></p>
<p id="socialicons3">
    <a href="http://dot-nettuts.blogspot.in"><img border="0" src="img/rss.png" /></a>
    <a href="http://dot-nettuts.blogspot.in"><img border="0" src="img/delicious.png" /></a>
    <a href="http://dot-nettuts.blogspot.in"><img border="0" src="img/facebook.png" /></a>
    <a href="http://dot-nettuts.blogspot.in"><img border="0" src="img/twitter.png" /></a>
    <a href="http://dot-nettuts.blogspot.in"><img border="0" src="img/yahoo.png" /></a>
</p>
------------------------------------------------------------------
<style type="text/css">
        p#socialicons img
        {
            /* 1st set of icons. Rotate them 360deg onmouseover and out */
            -moz-transition: all 0.8s ease-in-out;
            -webkit-transition: all 0.8s ease-in-out;
            -o-transition: all 0.8s ease-in-out;
            -ms-transition: all 0.8s ease-in-out;
            transition: all 0.8s ease-in-out;
        }
        p#socialicons img:hover
        {
            -moz-transform: rotate(360deg);
            -webkit-transform: rotate(360deg);
            -o-transform: rotate(360deg);
            -ms-transform: rotate(360deg);
            transform: rotate(360deg);
        }
        p#socialicons2 img
        {
            /* 2nd set of icons. Rotate them 60deg onmouseover and out */
            -moz-transition: all 0.2s ease-in-out;
            -webkit-transition: all 0.2s ease-in-out;
            -o-transition: all 0.2s ease-in-out;
            -ms-transition: all 0.2s ease-in-out;
            transition: all 0.2s ease-in-out;
        }
        p#socialicons2 img:hover
        {
            -moz-transform: rotate(70deg);
            -webkit-transform: rotate(70deg);
            -o-transform: rotate(70deg);
            -ms-transform: rotate(70deg);
            transform: rotate(70deg);
        }
        p#socialicons3 img
        {
            /* 3rd set of icons. Rotate them -360deg onmouseover ONLY. Note where the "transition prop is added */
        }
        p#socialicons3 img:hover
        {
            -moz-transition: all 0.5s ease-in-out;
            -webkit-transition: all 0.5s ease-in-out;
            -o-transition: all 0.5s ease-in-out;
            -ms-transition: all 0.5s ease-in-out;
            transition: all 0.5s ease-in-out;
            -moz-transform: rotate(-360deg);
            -webkit-transform: rotate(-360deg);
            -o-transform: rotate(-360deg);
            -ms-transform: rotate(-360deg);
            transform: rotate(-360deg);
        }
    </style>
-------------------------------------------------