Click here to Skip to main content
15,063,556 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....


XML
<%@ 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="U_id,U_name" 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>
                            <asp:TemplateField HeaderText="U_id">
                                <EditItemTemplate>
                                    <asp:Label ID="lbleditusrid" runat="server" Text='<%#Eval("U_id") %>' />
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblitemUsrid" runat="server" Text='<%#Eval("U_id") %>' />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="U_name">
                                <EditItemTemplate>
                                    <asp:Label ID="lbleditusr" runat="server" Text='<%#Eval("U_name") %>' />
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblitemUsr" runat="server" Text='<%#Eval("U_name") %>' />
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtftrusrname" runat="server" />
                                    <asp:RequiredFieldValidator ID="rfvusername" runat="server" ControlToValidate="txtftrusrname"
                                        Text="*" ValidationGroup="validaiton" />
                                </FooterTemplate>
                            </asp:TemplateField>
                            <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>
                            <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>
                            <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>
                            <%-- <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>--%>

                            <asp:TemplateField HeaderText="CategoryName">
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtCategoryName" runat="server" Text='<%#Eval("CategoryName") %>' />
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblCategoryName" runat="server" Text='<%#Eval("CategoryName") %>' />
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtftrCategoryName" runat="server" />
                                    <asp:RequiredFieldValidator ID="rfvCategoryName" runat="server" ControlToValidate="txtftrCategoryName"
                                        Text="*" ValidationGroup="validaiton" />
                                </FooterTemplate>
                            </asp:TemplateField>




                            <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>
                            <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>
                            <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>
                            <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>
                            <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>

                            <asp:TemplateField HeaderText="AreaName">
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtAreaName" runat="server" Text='<%#Eval("AreaName") %>' />
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblAreaName" runat="server" Text='<%#Eval("AreaName") %>' />
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtftrAreaName" runat="server" />
                                    <asp:RequiredFieldValidator ID="rfvAreaName" runat="server" ControlToValidate="txtftrAreaName"
                                        Text="*" ValidationGroup="validaiton" />
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="startdate">
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtstartdate" runat="server" Text='<%#Eval("startdate") %>' />
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblstartdate" runat="server" Text='<%#Eval("startdate") %>' />
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtftrstartdate" runat="server" />
                                    <asp:RequiredFieldValidator ID="rfvstartdate" runat="server" ControlToValidate="txtftrstartdate"
                                        Text="*" ValidationGroup="validaiton" />
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="enddate">
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtenddate" runat="server" Text='<%#Eval("enddate") %>' />
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblenddate" runat="server" Text='<%#Eval("enddate") %>' />
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtftrenddate" runat="server" />
                                    <asp:RequiredFieldValidator ID="rfvenddate" runat="server" ControlToValidate="txtftrenddate"
                                        Text="*" ValidationGroup="validaiton" />
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="ImagePath">
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtImagePath" runat="server" Text='<%#Eval("ImagePath") %>' />
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblImagePath" runat="server" Text='<%#Eval("ImagePath") %>' />
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtftrImagePath" runat="server" />
                                    <asp:RequiredFieldValidator ID="rfvImagePath" runat="server" ControlToValidate="txtftrImagePath"
                                        Text="*" ValidationGroup="validaiton" />
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="diffrence">
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtdiffrence" runat="server" Text='<%#Eval("diffrence") %>' />
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lbldiffrence" runat="server" Text='<%#Eval("diffrence") %>' />
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtftrdiffrence" runat="server" />
                                    <asp:RequiredFieldValidator ID="rfvdiffrence" runat="server" ControlToValidate="txtftrdiffrence"
                                        Text="*" ValidationGroup="validaiton" />
                                </FooterTemplate>
                            </asp:TemplateField>


                            <asp:TemplateField HeaderText="New User Details">
                                <ItemTemplate>
                                    <asp:LinkButton ID="Activate" runat="server" OnClick="Activate_Click" CommandName="Activate">Activate</asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </td>
            </tr>
        </table>
    </div>

    <br />

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
            <Columns>
                <asp:BoundField DataField="U_id" HeaderText="U_id" SortExpression="U_id" />
                <asp:BoundField DataField="U_name" HeaderText="U_name" SortExpression="U_name" />
                <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="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />

                <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" />
                <asp:BoundField DataField="AreaName" HeaderText="AreaName" SortExpression="AreaName" />
                 <asp:BoundField DataField="startdate" HeaderText="startdate" SortExpression="startdate" />
                  <asp:BoundField DataField="enddate" HeaderText="enddate" SortExpression="enddate" />
                   <asp:BoundField DataField="ImagePath" HeaderText="ImagePath" SortExpression="ImagePath" />
                    <asp:BoundField DataField="diffrence" HeaderText="diffrence" SortExpression="diffrence" />

            </Columns>
        </asp:GridView>

    <div>
        <asp:Label ID="lblresult" runat="server"></asp:Label>
    </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.U_id ,u.U_name, u.U_Email,s.ImageName ,s.Description,s.CategoryName,s.ADshop_name,s.ADShop_Address,s.ADshop_city,s.ADshop_mob,s.ADshop_Email,s.AreaName,s.startdate,s.enddate,s.ImagePath,s.diffrence from LOGIN u ,SlideShowTable s where u.U_id=s.U_id", 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.U_id ,u.U_name, u.U_Email,s.ImageName ,s.Description,s.CategoryName,s.ADshop_name,s.ADShop_Address,s.ADshop_city,s.ADshop_mob,s.ADshop_Email,s.AreaName,s.startdate,s.enddate,s.ImagePath,s.diffrence from LOGIN u ,SlideShowTable1 s where u.U_id=s.U_id", con);
        cmd.ExecuteNonQuery();

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

        GridView1.DataSource = ds;
        GridView1.DataBind();
        con.Close();
    }

    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["U_name"].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 txtCategoryName = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtCategoryName");

        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");
        TextBox txtAreaName = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtAreaName");
        TextBox txtstartdate = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtstartdate");
        TextBox txtenddate = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtenddate");
        TextBox txtImagePath = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtImagePath");
        TextBox txtdiffrence = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtdiffrence");
        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.CategoryName='" + txtCategoryName.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 + "',s.AreaName='" + txtAreaName.Text + "',s.startdate='" + txtstartdate.Text + "',s.enddate='" + txtenddate.Text + "',s.ImagePath='" + txtImagePath.Text + "',s.diffrence='" + txtdiffrence.Text + "' where s.U_id=" + userid + " and u.U_id= " + 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["U_id"].ToString());
        string username = gvDetails.DataKeys[e.RowIndex].Values["U_name"].ToString();
        //string imagename = gvDetails.DataKeys[e.RowIndex].Values["ImageName"].ToString();

        con.Open();
        OleDbCommand cmd = new OleDbCommand("delete from SlideShowTable  where U_id=" + 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, "U_name"));
            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 txtCategoryName = (TextBox)gvDetails.FooterRow.FindControl("txtftrCategoryName");

            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");
            TextBox txtAreaName = (TextBox)gvDetails.FooterRow.FindControl("txtftrAreaName");
            TextBox txtstartdate = (TextBox)gvDetails.FooterRow.FindControl("txtftrstartdate");
            TextBox txtenddate = (TextBox)gvDetails.FooterRow.FindControl("txtftrenddate");
            TextBox txtImagePath = (TextBox)gvDetails.FooterRow.FindControl("txtftrImagePath");
            TextBox txtdiffrence = (TextBox)gvDetails.FooterRow.FindControl("txtftrdiffrence");

            con.Open();
            OleDbCommand cmd = new OleDbCommand("insert into LOGIN u ,SlideShowTable s(U_name,U_Email,ImageName,Description,CategoryName,ADshop_name,ADShop_Address,ADshop_city,ADshop_mob,ADshop_Email,AreaName,startdate,enddate,ImagePath,diffrence) values('" + txtUsrname.Text + "','" + txtU_Email.Text + "','" + txtImageName.Text + "','" + txtDescription.Text + "','" + txtCategoryName.Text + "','" + txtADshop_name.Text + "','" + txtADshop_city.Text + "','" + txtADshop_city.Text + "','" + txtADshop_mob.Text + "','" + txtADshop_Email.Text + "','" + txtAreaName.Text + "','" + txtstartdate.Text + "','" + txtenddate.Text + "','" + txtdiffrence.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,CategoryName,ADshop_name,ADShop_Address,ADshop_city,ADShop_mob,ADshop_Email,AreaName,startdate,enddate,ImagePath,diffrence)SELECT ImageID,ImageName,Description,CategoryName,ADshop_name,ADShop_Address,ADshop_city,ADShop_mob,ADshop_Email,AreaName,startdate,enddate,ImagePath,diffrence,userid FROM SlideShowTable WHERE U_id=" + userid, con);
        int result = cmd.ExecuteNonQuery();
        //OleDbCommand cmd1 = new OleDbCommand("Delete from SlideShowTable WHERE U_id=" + userid, con);
        //result = cmd1.ExecuteNonQuery();

        con.Close();

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

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

        }

    }
}
Posted
v2
Comments
rmksiva 17-Apr-13 2:31am
   
May i know, What error youare Getting ?
Raj@88 17-Apr-13 2:47am
   
no error...am unable show data in table 2 in grid view 2..
Dnyaneshwar Kondbale 17-Apr-13 3:28am
   
First Thing check the
int result = cmd.ExecuteNonQuery(); in rotected void Activate_Click(object sender, EventArgs e) is working fine
after that check da.Fill(ds); return what in protected void BindEmployeeDetails1() methode.
Raj@88 17-Apr-13 3:34am
   
Dnyaneshwar sir...can i send u the project on ur mail id ...if yes plz send me ur mail id...

i checked all things ..bt not getting the solution ...can plz help me out

thanx
Dnyaneshwar Kondbale 17-Apr-13 4:53am
   
Yes Why not....

Please share your code in Google docs My email Id is dnyanehswar17@gmail.com

Dnyaneshwar
Raj@88 17-Apr-13 4:48am
   
Can anybody help me..?
sri senthil kumar 17-Apr-13 4:54am
   
have you checked whether value ur copying from table to table getting stored in the access DB?
Raj@88 17-Apr-13 5:02am
   
yes ..value is copied.
Dnyaneshwar Kondbale 17-Apr-13 5:28am
   
After the checked your code I found the below things..

In your SlideShowTable1 table U_id is Identity or What?

If its Identity then How can you join on table LOGIN u and SlideShowTable1 s where u.U_id=s.U_id.

can you show me the Database structure.

Correct me if I am wrong , :)
Raj@88 17-Apr-13 5:46am
   
am unable to send u..
Dnyaneshwar Kondbale 17-Apr-13 5:54am
   
I checked the code Please debug and check at the time of inserting value in SlideShowTable1 what is U_ID.???
Raj@88 17-Apr-13 6:04am
   
U_id is field that present in LOGIN table.

U_id,U_name,U_Email,U_Mobile,U_password
Dnyaneshwar Kondbale 17-Apr-13 6:14am
   
You try to check
where u.U_id=s.U_id
Here S.U_Id is in SlideShowTable1 table.Try to debug the code you get a solution.
Please correct me if I am wrong.

Dnyaneshwar Kondbale 17-Apr-13 6:18am
   
In BindEmployeeDetails1() function you write a query

OleDbCommand cmd = new OleDbCommand("Select u.U_id ,u.U_name, u.U_Email,s.ImageName ,s.Description,s.CategoryName,s.ADshop_name,s.ADShop_Address,s.ADshop_city,s.ADshop_mob,s.ADshop_Email,s.AreaName,s.startdate,s.enddate,s.ImagePath,s.diffrence from LOGIN u ,SlideShowTable1 s where u.U_id=s.U_id", con);

In above select Query you checked u.U_id=s.U_id, I thing its causes problem.

instead of cross join try left outer join
Raj@88 17-Apr-13 6:52am
   
i tried but not getting the solution

sir...give me ur mail id ...the id which u given is wrong..
Dnyaneshwar Kondbale 17-Apr-13 6:56am
   
srry its dnyaneshwar17@gmail.com
dnyanesh.k@hotmail.com
Raj@88 17-Apr-13 7:06am
   
kar diya mail...plz check it out..

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