网格视图中的问题 [英] problem in grid view

查看:87
本文介绍了网格视图中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在访问中使用两个网格视图和两个表...在第一个网格视图中为每一行给出激活链接按钮...当我单击激活链接按钮时,该特定行从一个表移动/复制到第二个表....但问题是,我想在网格视图2中显示第二个表中的数据...我在它上面工作......但我不能......请帮助我...... />

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

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

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]

Code blocks added[/Edit]

推荐答案

Very 1st thing you add commandname to the following line in your code

Very 1st thing you add commandname to the following line in your code
<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


now in in first grid rowcommand track the unique id of the row using following code and store in a label

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


Hope this helps you.....

Code blocks added[/Edit]


这篇关于网格视图中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆