简体   繁体   English

绑定另一个页面上的网格视图

[英]Databind a gridview on another page

I have a grid view (gridView1) on an webform1.aspx with a button that can trigger a popup window. 我在webform1.aspx上有一个网格视图(gridView1),带有一个可以触发弹出窗口的按钮。 The popup window links to webform2.aspx that allow users to import an excel file to get data. 弹出窗口链接到webform2.aspx,允许用户导入excel文件以获取数据。 The data are expected to be show on the grid view on webform1.aspx. 预期数据将显示在webform1.aspx的网格视图上。 However how can I databind the gridView1, once the excel file is loaded? 但是,一旦加载excel文件,我该如何对gridView1进行数据绑定?

I have some ideas to do it, not sure if the logic is correct. 我有一些想法可以做到,不确定逻辑是否正确。

webform1.aspx.cs webform1.aspx.cs

//tempDT is a DataTable type to store the data of the grid    
Session["data"] = tempDT;
/*Open a popup with webform2.aspx*/

webform2.aspx.cs webform2.aspx.cs

//Get data from original data table and add new data get from excel
DataTable tempDT = (DataTable)Session["data"];
/* Add new data from excel to tempDT here */
Session["data"] = tempDT;

But I don't have any ideas to Databind the grid view after that as I cannot call the grid view in webform2.aspx 但是在那之后我没有任何数据绑定网格视图的想法,因为我无法在webform2.aspx中调用网格视图

I am not sure will this help you are not 我不确定这对您有没有帮助

   GridView grv = ((GridView)this.Page.PreviousPage.FindControl("gridview1"));

but another way could the way you thinking, just make sure to do post back for webform1, like redirect to webform1 and on form load 但是另一种方式可以满足您的想法,只需确保为webform1做回发,例如重定向到webform1并在表单加载时

you can check that if session is not null then bind with session data 您可以检查session是否为null,然后与session数据绑定

What you want to do is: 您想要做的是:
1. When you click on button it will pop up a window(webform 2 you are saying) 1.单击按钮时,将弹出一个窗口(您说的是网络表单2)
2. Now User Load the data from Excel file. 2.现在,用户从Excel文件中加载数据。
3. you want to bind that data in Grid on web form1 3.您想将该数据绑定到Web Form1上的 Grid中

Ok, now create the process as below mentioned: 好的,现在创建如下所述的过程:

  1. Take a session variable, check if it is not null bind the data from it on webform1 as below: 采取会话变量,检查它是否不为null,如下所示将其数据绑定到webform1上:
 if (Session["ExcelData"]!=null) { //Code here of binding the grid DataTable dt= (DataTable)Session["ExcelData"]; GridView1.DataSource= dt; GridView1.DataBind(); } 
  1. Now go to second webform's button click on which you are loading the data from excel. 现在转到第二个Webform的按钮,单击该按钮可以从excel加载数据。
  2. Create a dataTable and fill it with data from excel(the data loaded from excel) 创建一个dataTable并用excel中的数据填充(从excel中加载的数据)
  3. and store that data table in Session as below: 并将该数据表存储在Session中,如下所示:

Session["ExcelData"]=dtExceldata; Session [“ ExcelData”] = dtExceldata;

  1. close the pop up window and call the GridBind Method. 关闭弹出窗口,然后调用GridBind方法。

UPDATED: 更新:

That's All. 就这样。 Hope this will help you 希望这个能对您有所帮助

You have to add the one more grid view in 'ebform2.aspx and put it inside the panel control which help you to hide the gridview. 您必须在'ebform2.aspx中再添加一个网格视图,并将其放在面板控件中,该控件可帮助您隐藏gridview。 In import button make panel visible so that the grid view with new value will appear at same page. 在导入按钮中,使面板可见,以便具有新值的网格视图将显示在同一页面上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM