Click here to Skip to main content
15,071,637 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
am using two grid views and two tables in access ...in 1st grid view activate link button is given for each row...when i click activate link button, than that particular row moved/copied from one table to 2nd table....but problem is that , i want show the data in 2nd table in grid view 2 ...i worked on it ...but i can't ...plz help me....
ASP
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .Gridview
        {
            font-family: Verdana;
            font-size: 10pt;
            font-weight: normal;
            color: black;
        }
    </style>

    <script type="text/javascript">
function ConfirmationBox(username) {

var result = confirm('Are you sure you want to delete '+username+' Details?' );
if (result) {

return true;
}
else {
return false;
}
}
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table align="center">
            <tr>
                <td height="100px">
                </td>
            </tr>
            <tr>
                <td>
                    <asp:GridView ID="gvDetails" runat="server" DataKeyNames="UserId,UserName" AutoGenerateColumns="false"
                        CssClass="Gridview" HeaderStyle-BackColor="#61A6F8" ShowFooter="true" HeaderStyle-Font-Bold="true"
                        HeaderStyle-ForeColor="White" OnRowCancelingEdit="gvDetails_RowCancelingEdit"
                        OnRowDeleting="gvDetails_RowDeleting" OnRowEditing="gvDetails_RowEditing" OnRowDataBound="gvDetails_RowDataBound"
                        OnRowUpdating="gvDetails_RowUpdating" OnRowCommand="gvDetails_RowCommand">
                        <columns>
                            <asp:TemplateField>
                                <edititemtemplate>
                                    <asp:ImageButton ID="imgbtnUpdate" CommandName="Update" runat="server" ImageUrl="~/Images/update.jpg"
                                        ToolTip="Update" Height="20px" Width="20px" />
                                    <asp:ImageButton ID="imgbtnCancel" runat="server" CommandName="Cancel" ImageUrl="~/Images/Cancel.jpg"
                                        ToolTip="Cancel" Height="20px" Width="20px" />
                                </edititemtemplate>
                                <itemtemplate>
                                    <asp:ImageButton ID="imgbtnEdit" CommandName="Edit" runat="server" ImageUrl="~/Images/Edit.jpg"
                                        ToolTip="Edit" Height="20px" Width="20px" />
                                    <asp:ImageButton ID="imgbtnDelete" CommandName="Delete" Text="Edit" runat="server"
                                        ImageUrl="~/Images/delete.jpg" ToolTip="Delete" Height="20px" Width="20px" />
                                </itemtemplate>
                                <footertemplate>
                                    <asp:ImageButton ID="imgbtnAdd" runat="server" ImageUrl="~/Images/AddNewitem.jpg"
                                        CommandName="AddNew" Width="30px" Height="30px" ToolTip="Add new User" ValidationGroup="validaiton" />
                                </footertemplate>
                            
                            <asp:TemplateField HeaderText="UserId">
                                <edititemtemplate>
                                    <asp:Label ID="lbleditusrid" runat="server" Text='<%#Eval("UserId") %>' />
                                </edititemtemplate>
                                <itemtemplate>
                                    <asp:Label ID="lblitemUsrid" runat="server" Text='<%#Eval("UserId") %>' />
                                </itemtemplate>
                            
                            <asp:TemplateField HeaderText="UserName">
                                <edititemtemplate>
                                    <asp:Label ID="lbleditusr" runat="server" Text='<%#Eval("UserName") %>' />
                                </edititemtemplate>
                                <itemtemplate>
                                    <asp:Label ID="lblitemUsr" runat="server" Text='<%#Eval("UserName") %>' />
                                </itemtemplate>
                                <footertemplate>
                                    <asp:TextBox ID="txtftrusrname" runat="server" />
                                    <asp:RequiredFieldValidator ID="rfvusername" runat="server" ControlToValidate="txtftrusrname"
                                        Text="*" ValidationGroup="validaiton" />
                                </footertemplate>
                            
                            <asp:TemplateField HeaderText="U_Email">
                                <edititemtemplate>
                                    <asp:TextBox ID="txtU_Email" runat="server" Text='<%#Eval("U_Email") %>' />
                                </edititemtemplate>
                                <itemtemplate>
                                    <asp:Label ID="lblU_Email" runat="server" Text='<%#Eval("U_Email") %>' />
                                </itemtemplate>
                                <footertemplate>
                                    <asp:TextBox ID="txtftrU_Email" runat="server" />
                                    <asp:RequiredFieldValidator ID="rfvU_Email" runat="server" ControlToValidate="txtftrU_Email"
                                        Text="*" ValidationGroup="validaiton" />
                                </footertemplate>
                            
                            <asp:TemplateField HeaderText="ImageName">
                                <edititemtemplate>
                                    <asp:TextBox ID="txtImageName" runat="server" Text='<%#Eval("ImageName") %>' />
                                </edititemtemplate>
                                <itemtemplate>
                                    <asp:Label ID="lblImageName" runat="server" Text='<%#Eval("ImageName") %>' />
                                </itemtemplate>
                                <footertemplate>
                                    <asp:TextBox ID="txtftrImageName" runat="server" />
                                    <asp:RequiredFieldValidator ID="rfvImageName" runat="server" ControlToValidate="txtftrImageName"
                                        Text="*" ValidationGroup="validaiton" />
                                </footertemplate>
                            
                            <asp:TemplateField HeaderText="Description">
                                <edititemtemplate>
                                    <asp:TextBox ID="txtDescription" runat="server" Text='<%#Eval("Description") %>' />
                                </edititemtemplate>
                                <itemtemplate>
                                    <asp:Label ID="lblDescription" runat="server" Text='<%#Eval("Description") %>' />
                                </itemtemplate>
                                <footertemplate>
                                    <asp:TextBox ID="txtftrDescription" runat="server" />
                                    <asp:RequiredFieldValidator ID="rfvDescription" runat="server" ControlToValidate="txtftrDescription"
                                        Text="*" ValidationGroup="validaiton" />
                                </footertemplate>
                            
                            <%-- <asp:TemplateField HeaderText="Description">
 <edititemtemplate>
 <asp:TextBox ID="txtDescription" runat="server" Text='<%#Eval("Description") %>'/>
 </edititemtemplate>
 <itemtemplate>
 <asp:Label ID="lblDescription" runat="server" Text='<%#Eval("Description") %>'/>
 </itemtemplate>
 <footertemplate>
 <asp:TextBox ID="txtftrDescription" runat="server"/>
  <asp:RequiredFieldValidator ID="rfvDescription" runat="server" ControlToValidate="txtftrDescription" Text="*" ValidationGroup="validaiton"/>
 </footertemplate>
 --%>
                            <asp:TemplateField HeaderText="ADshop_name">
                                <edititemtemplate>
                                    <asp:TextBox ID="txtADshop_name" runat="server" Text='<%#Eval("ADshop_name") %>' />
                                </edititemtemplate>
                                <itemtemplate>
                                    <asp:Label ID="lblADshop_name" runat="server" Text='<%#Eval("ADshop_name") %>' />
                                </itemtemplate>
                                <footertemplate>
                                    <asp:TextBox ID="txtftrADshop_name" runat="server" />
                                    <asp:RequiredFieldValidator ID="rfvADshop_name" runat="server" ControlToValidate="txtftrADshop_name"
                                        Text="*" ValidationGroup="validaiton" />
                                </footertemplate>
                            
                            <asp:TemplateField HeaderText="ADShop_Address">
                                <edititemtemplate>
                                    <asp:TextBox ID="txtADShop_Address" runat="server" Text='<%#Eval("ADShop_Address") %>' />
                                </edititemtemplate>
                                <itemtemplate>
                                    <asp:Label ID="lblADShop_Address" runat="server" Text='<%#Eval("ADShop_Address") %>' />
                                </itemtemplate>
                                <footertemplate>
                                    <asp:TextBox ID="txtftrADShop_Address" runat="server" />
                                    <asp:RequiredFieldValidator ID="rfvADShop_Address" runat="server" ControlToValidate="txtftrADShop_Address"
                                        Text="*" ValidationGroup="validaiton" />
                                </footertemplate>
                            
                            <asp:TemplateField HeaderText="ADshop_city">
                                <edititemtemplate>
                                    <asp:TextBox ID="txtADshop_city" runat="server" Text='<%#Eval("ADshop_city") %>' />
                                </edititemtemplate>
                                <itemtemplate>
                                    <asp:Label ID="lblADshop_city" runat="server" Text='<%#Eval("ADshop_city") %>' />
                                </itemtemplate>
                                <footertemplate>
                                    <asp:TextBox ID="txtftrADshop_city" runat="server" />
                                    <asp:RequiredFieldValidator ID="rfvADshop_city" runat="server" ControlToValidate="txtftrADshop_city"
                                        Text="*" ValidationGroup="validaiton" />
                                </footertemplate>
                            
                            <asp:TemplateField HeaderText="ADShop_mob">
                                <edititemtemplate>
                                    <asp:TextBox ID="txtADShop_mob" runat="server" Text='<%#Eval("ADShop_mob") %>' />
                                </edititemtemplate>
                                <itemtemplate>
                                    <asp:Label ID="lblADShop_mob" runat="server" Text='<%#Eval("ADShop_mob") %>' />
                                </itemtemplate>
                                <footertemplate>
                                    <asp:TextBox ID="txtftrADShop_mob" runat="server" />
                                    <asp:RequiredFieldValidator ID="rfvADShop_mob" runat="server" ControlToValidate="txtftrADShop_mob"
                                        Text="*" ValidationGroup="validaiton" />
                                </footertemplate>
                            
                            <asp:TemplateField HeaderText="ADshop_Email">
                                <edititemtemplate>
                                    <asp:TextBox ID="txtADshop_Email" runat="server" Text='<%#Eval("ADshop_Email") %>' />
                                </edititemtemplate>
                                <itemtemplate>
                                    <asp:Label ID="lblADshop_Email" runat="server" Text='<%#Eval("ADshop_Email") %>' />
                                </itemtemplate>
                                <footertemplate>
                                    <asp:TextBox ID="txtftrADshop_Email" runat="server" />
                                    <asp:RequiredFieldValidator ID="rfvADshop_Email" runat="server" ControlToValidate="txtftrADshop_Email"
                                        Text="*" ValidationGroup="validaiton" />
                                </footertemplate>
                            
                            <asp:TemplateField HeaderText="New User Details">
                                <itemtemplate>
                                    <asp:LinkButton ID="Activate" runat="server" OnClick="Activate_Click">Activate
                                </itemtemplate>
                            
                        </columns>
                    
                </td>
            </tr>
        </table>
    </div>
    
    <br />
    
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
            <columns>
                <asp:BoundField DataField="UserId" HeaderText="UserId" SortExpression="UserId" />
                <asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
                <asp:BoundField DataField="U_Email" HeaderText="U_Email" SortExpression="U_Email" />
                <asp:BoundField DataField="ImageName" HeaderText="ImageName" SortExpression="ImageName" />
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                <asp:BoundField DataField="ADshop_name" HeaderText="ADshop_name" SortExpression="ADshop_name" />
                <asp:BoundField DataField="ADShop_Address" HeaderText="ADShop_Address" SortExpression="ADshop_name" />
                <asp:BoundField DataField="ADshop_city" HeaderText="ADshop_city" SortExpression="ADshop_city" />
                <asp:BoundField DataField="ADShop_mob" HeaderText="ADShop_mob" SortExpression="ADShop_mob" />
                <asp:BoundField DataField="ADshop_Email" HeaderText="ADshop_Email" SortExpression="ADshop_Email" />
            </columns>
        
    
    <div>
        <asp:Label ID="lblresult" runat="server">
    </div>
    </form>
</body>
</html>
C#
using System;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page 
{

     protected   OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
   //  public OleDbConnection  con = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\NAGESH\\Desktop\\GridviewEditUpdateDelete - Copy\\App_Data\\DatabasePCG03.mdb;Persist Security Info=True");
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindEmployeeDetails();
                BindEmployeeDetails1();
            }
        }
        protected void BindEmployeeDetails()
        {
            con.Open();
           // OleDbCommand cmd = new OleDbCommand("Select  *  from LOGIN  , SlideShowTable  where LOGIN.UserId=SlideShowTable.UserId", con);
            OleDbCommand cmd = new OleDbCommand("Select u.UserId ,u.UserName, u.U_Email,s.ImageName ,s.Description,s.ADshop_name,s.ADShop_Address,s.ADshop_city,s.ADshop_mob,s.ADshop_Email from LOGIN u ,SlideShowTable s where u.UserId=s.UserId", con);
            cmd.ExecuteNonQuery();

            OleDbDataAdapter  da = new OleDbDataAdapter (cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            gvDetails.DataSource = ds;
            gvDetails.DataBind();
            con.Close();
            if (ds.Tables[0].Rows.Count > 0)
            {
                gvDetails.DataSource = ds;
                gvDetails.DataBind();
            }
            else
            {
                ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
                gvDetails.DataSource = ds;

                int columncount = gvDetails.Rows[0].Cells.Count;
                gvDetails.Rows[0].Cells.Clear();
                gvDetails.Rows[0].Cells.Add(new TableCell());
                gvDetails.Rows[0].Cells[0].ColumnSpan = columncount;
                gvDetails.Rows[0].Cells[0].Text = "No Records Found";
                gvDetails.DataBind();

            }

        }


        protected void BindEmployeeDetails1()
        {
            con.Open();
            // OleDbCommand cmd = new OleDbCommand("Select  *  from LOGIN  , SlideShowTable  where LOGIN.UserId=SlideShowTable.UserId", con);
            OleDbCommand cmd = new OleDbCommand("Select u.UserId ,u.UserName, u.U_Email,s.ImageName ,s.Description,s.ADshop_name,s.ADShop_Address,s.ADshop_city,s.ADshop_mob,s.ADshop_Email from LOGIN u ,SlideShowTable1 s where u.UserId=s.UserId", con);
            cmd.ExecuteNonQuery();

            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);

            GridView1.DataSource = ds;
            GridView1.DataBind();
            con.Close();
            //if (ds.Tables[0].Rows.Count > 0)
            //{
            //    GridView1.DataSource = ds;
            //    GridView1.DataBind();
            //}
            //else
            //{
            //    ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
            //    GridView1.DataSource = ds;

            //    int columncount = gvDetails.Rows[0].Cells.Count;
            //    GridView1.Rows[0].Cells.Clear();
            //    GridView1.Rows[0].Cells.Add(new TableCell());
            //    GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
            //    GridView1.Rows[0].Cells[0].Text = "No Records Found";
            //    GridView1.DataBind();

            //}

        }





        protected void gvDetails_RowEditing(object sender, GridViewEditEventArgs e)
        {
            gvDetails.EditIndex = e.NewEditIndex;
            BindEmployeeDetails();
        }

        protected void gvDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            
            int userid = Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Value.ToString());
            //ring user = gvDetails.DataKeys[e.RowIndex].Values["UserName"].ToString();
            
            string username = gvDetails.DataKeys[e.RowIndex].Values["UserName"].ToString();
            //string imagename = gvDetails.DataKeys[e.RowIndex].Values["ImageName"].ToString();
           
            TextBox txtU_Email = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtU_Email");
            TextBox txtImageName = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtImageName");
            TextBox txtDescription = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtDescription");
            TextBox txtADshop_name = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtADshop_name");
            TextBox txtADShop_Address = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtADShop_Address");
            TextBox txtADshop_city = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtADshop_city");
            TextBox txtADshop_mob = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtADshop_mob");
            TextBox txtADshop_Email = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtADshop_Email");
            con.Open();
            //OleDbCommand cmd = new OleDbCommand("UPDATE LOGIN u ,SlideShowTable s SET u.U_Email = '" + txtU_Email.Text + "',s.ImageName='" + txtImageName.Text + "',s.Description='" + txtDescription.Text + "',s.ADshop_name='" + txtADshop_name.Text + "',s.ADShop_Address='" + txtADShop_Address.Text + "',s.ADshop_city='" + txtADshop_city.Text + "',s.ADshop_mob='" + txtADshop_mob.Text + "',s.ADshop_Email='" + txtADshop_Email.Text + "' where s.UserId and u.UserId= " + userid, con);
           // OleDbCommand cmd = new OleDbCommand("UPDATE LOGIN u ,SlideShowTable s SET u.U_Email = '" + txtU_Email.Text + "',s.ImageName='" + txtImageName.Text + "',s.Description='" + txtDescription.Text + "',s.ADshop_name='" + txtADshop_name.Text + "',s.ADShop_Address='" + txtADShop_Address.Text + "',s.ADshop_city='" + txtADshop_city.Text + "',s.ADshop_mob='" + txtADshop_mob.Text + "',s.ADshop_Email='" + txtADshop_Email.Text + "' where s.UserId=" + userid, con);
            OleDbCommand cmd =new OleDbCommand("UPDATE LOGIN u ,SlideShowTable s SET u.U_Email = '" + txtU_Email.Text + "',s.ImageName='" + txtImageName.Text + "',s.Description='" + txtDescription.Text + "',s.ADshop_name='" + txtADshop_name.Text + "',s.ADShop_Address='" + txtADShop_Address.Text + "',s.ADshop_city='" + txtADshop_city.Text + "',s.ADshop_mob='" + txtADshop_mob.Text + "',s.ADshop_Email='" + txtADshop_Email.Text + "' where s.UserId=" + userid +" and u.UserId= " + userid, con);
            
            
            
            cmd.ExecuteNonQuery();
            con.Close();
            lblresult.ForeColor = Color.Green;
            lblresult.Text = username + " Details Updated successfully";
            gvDetails.EditIndex = -1;
            BindEmployeeDetails();
        }

        protected void gvDetails_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gvDetails.EditIndex = -1;
            BindEmployeeDetails();
        }

        protected void gvDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int userid = Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Values["UserId"].ToString());
            string username = gvDetails.DataKeys[e.RowIndex].Values["UserName"].ToString();
            //string imagename = gvDetails.DataKeys[e.RowIndex].Values["ImageName"].ToString();

            con.Open();
            OleDbCommand cmd = new OleDbCommand("delete from SlideShowTable  where UserId=" + userid, con);
            int result = cmd.ExecuteNonQuery();
            con.Close();
            if (result == 1)
            {
                BindEmployeeDetails();
                lblresult.ForeColor = Color.Red;
                lblresult.Text = username + " details deleted successfully";
            }
        }

        protected void gvDetails_RowDataBound(object sender, GridViewRowEventArgs e)
        {
          
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //getting username from particular row
                string username = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "UserName"));
                string imagename = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "ImageName"));

                //identifying the control in gridview
                ImageButton lnkbtnresult = (ImageButton)e.Row.FindControl("imgbtnDelete");
                //LinkButton lnkresult = (LinkButton)e.Row.FindControl("Activate");

                //raising javascript confirmationbox whenver user clicks on link button
                if (lnkbtnresult != null)
                {
                    lnkbtnresult.Attributes.Add("onclick", "javascript:return ConfirmationBox('" + username + "')");
                }

            }
        }

        protected void gvDetails_RowCommand(object sender, GridViewCommandEventArgs e)
        {
           if(e.CommandName.Equals("AddNew"))
           {
               TextBox txtUsrname = (TextBox)gvDetails.FooterRow.FindControl("txtftrusrname");
               TextBox txtU_Email = (TextBox)gvDetails.FooterRow.FindControl("txtftrU_Email");
               TextBox txtImageName = (TextBox)gvDetails.FooterRow.FindControl("txtftrImageName");
               TextBox txtDescription = (TextBox)gvDetails.FooterRow.FindControl("txtftrDescription");
               TextBox txtADshop_name = (TextBox)gvDetails.FooterRow.FindControl("txtftrADshop_name");
               TextBox txtADShop_Address = (TextBox)gvDetails.FooterRow.FindControl("txtftrADShop_Address");
               TextBox txtADshop_city = (TextBox)gvDetails.FooterRow.FindControl("txtftrADshop_city");
               TextBox txtADshop_mob = (TextBox)gvDetails.FooterRow.FindControl("txtftrADshop_mob");
               TextBox txtADshop_Email = (TextBox)gvDetails.FooterRow.FindControl("txtftrADshop_Email");
               
               con.Open();
               OleDbCommand cmd = new OleDbCommand("insert into LOGIN u ,SlideShowTable s(UserName,U_Email,ImageName,Description,ADshop_name,ADShop_Address,ADshop_city,ADshop_mob,ADshop_Email) values('" + txtUsrname.Text + "','" + txtU_Email.Text + "','" + txtImageName.Text + "','" + txtDescription.Text + "','" + txtADshop_name.Text + "','" + txtADshop_city.Text + "','" + txtADshop_city.Text + "','" + txtADshop_mob.Text + "','" + txtADshop_Email.Text + "')", con);
              int result= cmd.ExecuteNonQuery();
              con.Close();
               if(result==1)
               {
                   BindEmployeeDetails();
                   lblresult.ForeColor = Color.Green;
                   lblresult.Text = txtUsrname.Text + " Details inserted successfully";
               }
               else
               {
                   lblresult.ForeColor = Color.Red;
                   lblresult.Text = txtUsrname.Text + " Details not inserted"; 
               }
               

           }
            

        }

        protected void gvDetails_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void Activate_Click(object sender, EventArgs e)
        {

            LinkButton lnk = sender as LinkButton;
            //Response.Redirect("Default2.aspx");
            GridViewRow gridrow = lnk.NamingContainer as GridViewRow;
            int userid = Convert.ToInt32(gvDetails.DataKeys[gridrow.RowIndex].Value.ToString());
            string username = gridrow.Cells[0].Text;
            con.Open();
            OleDbCommand cmd = new OleDbCommand("INSERT INTO SlideShowTable1 (ImageID,ImageName,Description,CategoryID,ADshop_name,ADShop_Address,ADshop_city,ADShop_mob,ADshop_Email)SELECT ImageID,ImageName,Description,CategoryID,ADshop_name,ADShop_Address,ADshop_city,ADShop_mob,ADshop_Email FROM SlideShowTable WHERE UserId=" + userid, con);
            int result = cmd.ExecuteNonQuery();
            con.Close();

            if (result > 0)
            {
                BindEmployeeDetails();
                BindEmployeeDetails1();

                ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('" + username + " Add id activated successfully')", true);

            }

        }

}
[Edit]Code blocks added[/Edit]
Posted
Updated 14-Apr-13 6:00am
v3

1 solution

Very 1st thing you add commandname to the following line in your code
ASP
<asp:LinkButton ID="Activate" runat="server" CommanName="Activate">Activate

now in in first grid rowcommand track the unique id of the row using following code and store in a label
C#
//u must have lblUniqueid and your tables unique id binded to it

Label lblUniqueValue=(Label)e.Row.FindControl("lblUniqueid");
string uniquevalue=lblUniqueValue.Text;

//Perform database operation and insert the row from 1st table to 2nd table
//delete the particular row from 1st table

//fill both grids once again you will have your data in proper place.

e.g grdview1.datasource=Table1;
grdview1.dataBind();

grdview2.datasource=Table2;
grdview2.dataBind();

Hope this helps you.....

[Edit]Code blocks added[/Edit]
   
v2
Comments
Raj@88 14-Apr-13 12:37pm
   
not working...:(
Raj Parashar 14-Apr-13 13:22pm
   
what is not working tell me the exact situation and i shall let you know the exact correct answer and do let me know what u did?
Raj@88 14-Apr-13 13:48pm
   
u told me two things..i did 1st thing properly working...2nd thing is not working...
Raj Parashar 14-Apr-13 13:52pm
   
again i am asking what is not working? Are u able to get value in the string? Are u able to insert data in second table? Are u able to delete data from 1st table? are u able to fill grids once again?
Raj@88 14-Apr-13 14:13pm
   
AM NOT ABLE TO FETCH THE VALUE IN 2ND GIRD FROM 2ND TABLE..
Raj Parashar 14-Apr-13 14:16pm
   
have fetched data in a dataset and assigned it as a data source to 2nd grid from 2nd table? if yes then check through sql query whether you have data in 2nd table or not.
Raj@88 14-Apr-13 14:23pm
   
all is working sir..

query also correct..
i have data in 2nd table..
Raj Parashar 14-Apr-13 14:26pm
   
can you paste the code which you are using for filling 2nd grid? and yes are u using any update panel on the form? if yes then you need to update the panel after filling the 2nd grid to display data.
Raj@88 14-Apr-13 14:29pm
   
plz check the code above....am not using update panel...
Raj Parashar 14-Apr-13 14:42pm
   
use the following method to fill data table and assign it to Gridview and if still it doesn't work then i need to see your code which you can send me to parasharmba@gmail.com

con.open()
OleDBCommand cmd=new OleDbCommand();
cmd.CommandText="Select * from Table2";
OledbDataAdapter adp=new OledbdataAdapter(cm.CommandText,con);
Datatable dt=new Datatable();
adp.fill(dt);

Gridview2.datasource=dt;
Gridview2.DataBind();
Raj Parashar 14-Apr-13 15:14pm
   
Is it done?
Raj@88 15-Apr-13 2:33am
   
i had send u mail ..plz check it out..thanx
Raj Parashar 15-Apr-13 5:46am
   
ur rectified solution hasa been posted back to you. Check and confirm.
Raj@88 15-Apr-13 6:22am
   
Thanx a lot sir....:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900