如何使用asp.net将数据从form1中的datalist传输到form2中的gridview [英] how to transfer datas from datalist in form1 to gridview in form2 using asp.net

查看:76
本文介绍了如何使用asp.net将数据从form1中的datalist传输到form2中的gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的DataList.aspx代码

 <   asp:DataList     ID   =   DataList1    runat  < span class =code-keyword> =  server      ItemStyle-CssClass   =  item1  

DataKeyField = BookId

< span class =code-attribute> CellPadding = 1 GridLines = 两者 < span class =code-attribute> RepeatColumns = 1 BorderWidth = 1px

< span class =code-attribute> onupdatecommand = DataList1_UpdateCommand < span class =code-attribute>

< span class =code-attribute> ondeletecommand = DataList1_DeleteCommand1

< span class =code-attribute> oneditcommand = DataList1_EditCommand



< span class =code-attribute> oncancelcommand = DataList1_CancelCommand1 ForeColor = # 333333

< span class =code-attribute> onitemcommand = DataList1_ItemCommand >
< itemtemplate >

< < span class =code-leadattribute> fieldset style = widt h:550px >

< span > < div id = divname style = padding-removed5px; >
< img src =' 资源/ <% #Eval( ImageUpl oad)%>' width = 90px 高度 = 90px 样式 = padding-left:40px alt = 无图像 / > < br / >
BookName: <% #DataBinder.Eval(Container.DataItem, BookName)%> < br / >
作者: <% #DataBinder.Eval(Container.DataItem, 作者)%> < br / >
发布商: <% #DataBinder.Eval(Container.DataItem, Publisher)%> < br < span class =code-attribute> / >
价格: <%#DataBinder.Eval(Container.DataItem, 价格)%> < br < span class =code-attribute> / >

< asp:ImageButton < span class =code-attribute> ID = ImgEdit runat = server ImageUrl = 〜/ Resources\imagesneww.jpg CommandName = 编辑 / >
< asp:ImageButton ID = ImageDelete runat = server ImageUrl = 〜/ Resources \edit-delete-icon.png CommandName = 删除 CausesValidation = < span class =code-keyword> false / >
< asp:ImageButton ID = ImageSend runat = 服务器 ImageUrl = 〜/ Resources\send.jpg CommandName = 发送 CausesValidation = false / >
< / div > < / span > < / fieldset > ;
< / itemtemplate >

解决方案

使用会话存储数据表。



示例在填写数据表后的表单1中将数据存储在会话中

会话[ 数据] = dt; 

//这里dt是包含您数据的表格



在表格2中从数据表中获取数据

代码

 DataTable dt =  new  DataTable(); 
dt =(DataTable)会话[ 数据];


this is my DataList.aspx code

<asp:DataList ID="DataList1" runat="server"  ItemStyle-CssClass="item1"

           DataKeyField="BookId" 

            CellPadding="1" GridLines="Both" RepeatColumns="1"  BorderWidth="1px"

            onupdatecommand="DataList1_UpdateCommand" 

            ondeletecommand="DataList1_DeleteCommand1" 

            oneditcommand="DataList1_EditCommand" 

        

            oncancelcommand="DataList1_CancelCommand1" ForeColor="#333333" 

            onitemcommand="DataList1_ItemCommand" >      
         <itemtemplate>
     
      <fieldset style="width:550px">

      <span> <div id="divname" style="padding-removed5px;">
             <img src='Resources/<%#Eval("ImageUpload") %>' width="90px" height="90px" style="padding-left:40px" alt="No Image" /><br /> 
      BookName : <%#DataBinder.Eval(Container.DataItem, "BookName")%><br />
        Author : <%#DataBinder.Eval(Container.DataItem, "Author")%><br />
        Publisher : <%#DataBinder.Eval(Container.DataItem, "Publisher")%><br />
        Price : <%#DataBinder.Eval(Container.DataItem, "Price")%><br />
       
   <asp:ImageButton ID="ImgEdit" runat="server" ImageUrl="~/Resources\imagesneww.jpg" CommandName="Edit" />     
        <asp:ImageButton ID="ImageDelete" runat="server" ImageUrl="~/Resources\edit-delete-icon.png" CommandName="Delete" CausesValidation="false"/>
         <asp:ImageButton ID="ImageSend" runat="server" ImageUrl="~/Resources\send.jpg" CommandName="Send"  CausesValidation="false"/>
      </div></span></fieldset>
        </itemtemplate>

解决方案

Use Session to store Datatable.

Example In form 1 after filling your data table store your data in a session

Session["Data"] = dt;

//Here dt is the table containing your data

In form 2 get the data back from datatable
Code

DataTable dt = new DataTable();
dt = (DataTable)Session["Data"];


这篇关于如何使用asp.net将数据从form1中的datalist传输到form2中的gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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