父窗体向子窗体传值

在ASP.NET应用中,尝试通过LinkButton点击事件使用JavaScript的showModalDialog方法打开子窗体,并传入父窗体Label控件的值。然而,子窗体的数据未能正确绑定,Label3仍然显示初始值。问题在于传值的方式是否正确。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、父窗体:
C# code
<ItemTemplate> <asp:LinkButton ID="LinkButton5" runat="server" ForeColor="#000066">查看</asp:LinkButton> <asp:Label ID="Label2" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "F_name")%>' Visible="False" Width="0px"></asp:Label> </ItemTemplate>


C# code
if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton l = (LinkButton)e.Row.FindControl("LinkButton5"); Label b = (Label)e.Row.FindControl("Label2"); string Temp = b.Text.ToString(); l.Attributes.Add("onclick", "window.showModalDialog('ContractParticularData.aspx?id="+Temp+"','window','dialogWidth:880px;DialogHeight=700px;status:no;help:no;resizable:yes;');window.location='#';"); }

2、子窗体:
HTML code
<tr> <td class="style3">客户名称:</td> <td class="style1"> <asp:Label ID="Label3" runat="server" Text="Label3"></asp:Label> </td> </tr>

C# code
string IDStr = Request.QueryString["id"].ToString(); OleDbConnection sqlConn = DB.CreateConn(); sqlConn.Open(); string sqlStr = "select * from XXXX where F_name='" + IDStr.ToString() + "'"; OleDbCommand MyCommand = new OleDbCommand(sqlStr, sqlConn); OleDbDataReader MyReader = MyCommand.ExecuteReader(); while(MyReader.Read()) { this.Label3.Text = MyReader["XXX"].ToString(); } sqlConn.Close();



结果:子窗体数据没绑上,Label3还是显示Lable3,请问这样传值对吗?

回答:

if (e.Row.RowType == DataControlRowType.DataRow)
  {
  LinkButton l = (LinkButton)e.Row.FindControl("LinkButton5");
  Label b = (Label)e.Row.FindControl("Label2");
  string Temp = b.Text.ToString();
  l.Attributes.Add("onclick", "window.showModalDialog('ContractParticularData.aspx?id="+Server.UrlEncode(Temp)+"','window','dialogWidth:880px;DialogHeight=700px;status:no;help:no;resizable:yes;');window.location='#';");

  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值