我做了一个上下的框架,上面连接有个页面top.aspx,top页面有一个datagrid1绑定了数据 ,datagird上做了一个按钮,我想通过点击按钮时会得到一个ID,通过ID查询数据库,得到一个PID然后刷新下面的那个页面,下面那个页面查询数据库时根据上个页面传过来的PID做为查询数据库的条件,然后在绑定到下面这个页面的datagrid上......
随便还问一下Session变量可以给他赋个空值吗?
随便还问一下Session变量可以给他赋个空值吗?
<frameset border="0" frameSpacing="0" rows="90,78%,32" frameBorder="0">
<frame id="topFrame" name="topFrame" src="top.aspx" scrolling="no" noresize >
<frameset cols="145,10,*" id="mainindex">
<frame id="menuFrame" name="menuFrame" src="LeftMenu.htm" frameBorder="no" noResize scrolling="no">
<frame src="default.htm" frameBorder="no" noResize scrolling="no">
<frame id="mainFrame" name="mainFrame" src="webform1.aspx">
</frameset>
<frame name="bottomFrame" src="bottomFrame.htm" noResize scrolling="no">
</frameset>
<asp:datagrid id="DataGrid1" runat="server">
<Columns>
<asp:BoundColumn Visible="False" DataField="id" ReadOnly="True" HeaderText="关键字"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button id="Button2" runat="server" Text="Button" CommandName="GetIt"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>添加ItemCommand事件处理程序:
private void DataGrid1_ItemCommand(object source, DataGridCommandEventArgs e)
{
if (e.CommandName == "GetID")
{
string id = e.Item.Cells[0].Text; string pID = id;//此处省略根据id从数据库读出pID的代码 Page.RegisterClientScriptBlock("", "<script>parent.mainFrame.location.href='webform1.aspx?pID="+pID+"';</script>");
}
}
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
string pID = Request.QueryString["pID"];
if(pID!=null)
BindData(pID);
}
}private void BindData(string pID)
{
System.Data.OleDb.OleDbConnection cnn = new System.Data.OleDb.OleDbConnection("连接字符串");
System.Data.OleDb.OleDbCommand cm = new System.Data.OleDb.OleDbCommand();
cm.Connection = cnn;
cm.CommandText = "Select * From Table1 Where pID = @par"; cm.Parameters.Add("@par",System.Data.OleDb.OleDbType.VarChar);
cm.Parameters["@par"].Value = pID;
System.Data.OleDb.OleDbDataAdapter da = new OleDbDataAdapter(cm);
DataTable dt = new DataTable();
da.FillSchema(dt);
this.DataGrid1.DataSource = dt;
this.DataGrid1.DataBind();
}