网格视图中的问题

问题描述:

在访问中使用两个网格视图和两个表...在第一个网格视图中为每一行给出激活链接按钮...当我单击激活链接按钮时,该特定行从一个表移动/复制到第二个表....但问题是,我想在网格视图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("
								

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]