在Table中动态生成的TextBox无法在PostBack时刷新数据

wagezhou 2011-11-29 03:40:57
问题如题,请高手帮忙看看问题在哪?

1.不用Textbox时,在点击DropDownList时,页面PostBack后,Table是可以刷新数据的(代码如下)
test.aspx:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem Value="1元">苹果</asp:ListItem>
<asp:ListItem Value="2元">桔子</asp:ListItem>
</asp:DropDownList>
<asp:Table ID="Table1" runat="server">
</asp:Table>
</div>
</form>
</body>
</html>
test.aspx.vb
Partial Class test
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim i As Integer
Dim myRow As New TableRow
For i = 0 To 1
Dim myCell As New TableCell
Select Case i
Case 0
myCell.Text = DropDownList1.SelectedItem.Text
Case 1
myCell.Text = DropDownList1.SelectedItem.Value
End Select
myRow.Cells.Add(myCell)
Next
Table1.Rows.Add(myRow)
End Sub
End Class
2.在Table中动态生成了TextBox,以便我编辑修改的需要,但是在点击DropDownList时,页面PostBack后,页面显示的数据不变(代码如下):
text1.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test1.aspx.vb" Inherits="test1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem Value="1元">苹果</asp:ListItem>
<asp:ListItem Value="2元">桔子</asp:ListItem>
</asp:DropDownList>
<asp:Table ID="Table1" runat="server">
</asp:Table>
</div>
</form>
</body>
</html>
test1.aspx.vb
Partial Class test1
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim i As Integer
Dim myRow As New TableRow
For i = 0 To 1
Dim myCell As New TableCell
Select Case i
Case 0
Dim myTextBox As New TextBox
myTextBox.Text = DropDownList1.SelectedItem.Text
myCell.Controls.Add(myTextBox)
Case 1
Dim myTextBox As New TextBox
myTextBox.Text = DropDownList1.SelectedItem.Value
myCell.Controls.Add(myTextBox)
End Select
myRow.Cells.Add(myCell)
Next
Table1.Rows.Add(myRow)
End Sub
End Class
...全文
64 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wagezhou 2011-11-29
  • 打赏
  • 举报
回复
我自己顶一下

另外补充一点,如果不是动态生成的TextBox,在PostBack之后也能刷新数据。

但为什么动态生成的TextBox,就不行呢?或者说,谁能教我如何实现呢?
wagezhou 2011-11-29
  • 打赏
  • 举报
回复
上面的情况1,是正常情况,不是我要提的问题,我只是举个例子。
情况2,是我的问题,请高手看看我的问题出在哪里?谢谢!

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧