gridview复选框将选定的行添加到另一个页面中的另一个网格视图 [英] gridview checkbox selected rows to another grid view in another page

查看:69
本文介绍了gridview复选框将选定的行添加到另一个页面中的另一个网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

选中选中的行或到另一页中另一个girdview的行,如果有的话,请将代码发送给我

第1页

checkbox selected row or rows to another girdview in another page please send me the code if you have it

page 1

<table>
        <tr>
            <td>
                <table>
                    <tr>
                        <td>
                            <table>
                                <tr>
                                    <td>
                                        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3"

                                            GridLines="None" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px"

                                            CellSpacing="1"

                                            AutoGenerateSelectButton="false" >
                                            <Columns>
                                                <asp:TemplateField>
                                                    <ItemTemplate>
                                                        <input type ="checkbox" value="" onclick='addthis(this,<%#Eval("EmpSalary") %>)' />

                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField>
                                                    <ItemTemplate>
                                                        <%# Eval("EmpName") %>
                                                    </ItemTemplate>
                                                </asp:TemplateField>

                                                <asp:TemplateField HeaderText="Emp Salary">
                                                    <ItemTemplate>
                                                       <%# Eval("EmpSalary") %>
                                                    </ItemTemplate>
                                             </asp:TemplateField>
                                            </Columns>
                                            <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
                                            <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
                                            <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
                                            <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                                            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
                                        </asp:GridView>
                                        <input type="text"  id="resdiv" value="0" />
                                        <asp:HiddenField ID="hidden1" runat="server" />
                                        <asp:Button ID="bbbtbn" runat="server" Width="50px" onclick="bbbtbn_Click" />
                                        <input type="text" id="txtxt"  />

                                    </td>
                                </tr>
                            </table>

                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>




第2页




page 2

<table>
                                <tr>
                                    <td>
                                        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3"

                                            GridLines="None" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px"

                                            CellSpacing="1"

                                            AutoGenerateSelectButton="false" >
                                            <Columns>

                                            </Columns>
                                            <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
                                            <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
                                            <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
                                            <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                                            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
                                        </asp:GridView>


                                    </td>
                                </tr>
                            </table>

推荐答案

首先在page_load上绑定gridview
然后
在click事件中,编写以下代码

first of all bind gridview on page_load
then
In the click event write the below code

foreach(Gridviewrow gvr in Gridview1.Rows)

{

if(((CheckBox)gvr.findcontrol("CheckBox1")).Checked == true)

{

int uPrimaryid= gvr.cells["uPrimaryID"];
}
}



您将获得基本ID

调用selectdata(uPrimaryid)它将返回数据集

session ["ds"] = selectdata(uPrimaryid)或

将其添加到querystring ... aspx?id = uPrimaryid

重定向到另一页

获取querstring request.querstring("id")

调用方法selectdata(uPrimaryid)

使用gridview.databind()进行绑定



you will get primaryid

call selectdata(uPrimaryid) it will return data set

session["ds"]=selectdata(uPrimaryid) or

add it in querystring ...aspx?id=uPrimaryid

redirect to another page

get querstring request.querstring("id")

call method selectdata(uPrimaryid)

bind using gridview.databind();



您可以使用以下步骤获取解决方案.
1.第1页
单击复选框时,请存储行的主要ID,并通过以下两种方式之一将其传递到第二页(上一页的findcontrol,会话,Cookie,查询字符串).
第2页
一旦具有rowid,便用该行ID命中数据库,并将结果绑定到网格视图中.


2.制作已选定行的数据表
将其存储在会话中
将该会话数据表绑定到gridview.

解决问题后,请标记为答案.
Hi,
You can get your solution by using following steps.
1. Page1
on clicking of checkbox please store primary id of row and pass it to the second page by either of way(findcontrol of previous page, session, cookie, querystring).
Page2
once you have rowid hit your database with that row id and get your result bind in grid view.


2. make a datatable of row that has been selected
store that in session
bind that session datatable to gridview.

Pleas mark as answer when you done with your problems.


创建一个对象,就像您的gridview列一样.当您在gridview中检查一行时,将该数据绑定到对象.然后,当您从一个页面导航到另一个页面时,将该对象保留在页面会话中,并将该对象绑定到另一页面的gridview中.最好的方法是使用对象和列表数组.
create an object just like ur gridview columns.when u checked a row in gridview bind that data to object. and after when u r navigating from one page to anther keep this object in page session and bind this object to gridview in another page.the best thing is use objects and list arrays.


这篇关于gridview复选框将选定的行添加到另一个页面中的另一个网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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