C#web页面中的datalist控件里放了一个TextBox为什么获取不到TextBox的值
<ItemTemplate><tr><td><asp:LabelID="Label1"runat="server"Text='<%#Eval("OrderNum")%>'...
<ItemTemplate>
<tr>
<td ><asp:Label ID="Label1" runat="server" Text='<%# Eval("OrderNum") %>' CssClass=""></asp:Label> </td>
<td ><asp:Label ID="Label2" runat="server" Text='<%# Eval("MIID") %>' CssClass=""></asp:Label> </td>
<td ><asp:Label ID="Lable3" runat="server" Text='<%# Eval("MIName") %>' CssClass=""></asp:Label> </td>
<td ><asp:Label ID="Label4" runat="server" Text='<%# Eval("Layout") %>' CssClass=""></asp:Label> </td>
<td ><asp:Label ID="Label5" runat="server" Text='<%# Eval("MIUrl") %>' CssClass=""></asp:Label> </td>
<%--<td ><asp:Label ID="Label6" runat="server" Text='<%# Eval("IconLink") %>' CssClass=""></asp:Label> </td>--%>
<td><asp:TextBox ID="TextBox3" runat="server" Text='<%# Eval("IconLink") %>' ReadOnly="true" OnDisposed="TextBox3_Disposed" OnTextChanged="TextBox3_TextChanged"></asp:TextBox></td>
<td>
<%--
<span><Hi:ImageLinkButton ID="btnReviewUpdate" runat="server" CommandName="Update" Visible=<%# Eval("MsgType").ToString() == "未处理" %> IsShow="false" CommandArgument='<%# Eval("FeedBackNotifyID")%>' Text="处理" /></span>
<span><Hi:ImageLinkButton ID="btnReviewDelete" runat="server" CommandName="Delete" Visible=<%# Eval("MsgType").ToString() != "未处理" %> IsShow="true" CommandArgument='<%# Eval("FeedBackNotifyID")%>' Text="删除" /></span>
--%>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Add" CommandArgument="Add" >添加</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Edit" CommandArgument="Edit">编辑</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="Update" CommandArgument="Update" OnClick="LinkButton3_Click">更新</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" runat="server" CommandName="Cancel" CommandArgument="Cancel">取消</asp:LinkButton>
<asp:LinkButton ID="LinkButton5" runat="server" CommandName="Delete" CommandArgument="Delete">删除</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
protected void LinkButton3_Click(object sender, EventArgs e)
{
//TextBox t = e.Item.FindControl("TextBox3") as TextBox;
//Label t = Page.FindControl("dtlist").Controls[1] as Label;
System.Web.UI.Page p = new System.Web.UI.Page();
TextBox t=p.FindControl("TextBox3") as TextBox;
Response.Write("<script type='text/javascript'>alert('" + t.Text + "')</script>");
//ViewState["temp"] = t.Text.ToString();
}
是因为不是page页面的控件,所以不能直接获取到吗 展开
<tr>
<td ><asp:Label ID="Label1" runat="server" Text='<%# Eval("OrderNum") %>' CssClass=""></asp:Label> </td>
<td ><asp:Label ID="Label2" runat="server" Text='<%# Eval("MIID") %>' CssClass=""></asp:Label> </td>
<td ><asp:Label ID="Lable3" runat="server" Text='<%# Eval("MIName") %>' CssClass=""></asp:Label> </td>
<td ><asp:Label ID="Label4" runat="server" Text='<%# Eval("Layout") %>' CssClass=""></asp:Label> </td>
<td ><asp:Label ID="Label5" runat="server" Text='<%# Eval("MIUrl") %>' CssClass=""></asp:Label> </td>
<%--<td ><asp:Label ID="Label6" runat="server" Text='<%# Eval("IconLink") %>' CssClass=""></asp:Label> </td>--%>
<td><asp:TextBox ID="TextBox3" runat="server" Text='<%# Eval("IconLink") %>' ReadOnly="true" OnDisposed="TextBox3_Disposed" OnTextChanged="TextBox3_TextChanged"></asp:TextBox></td>
<td>
<%--
<span><Hi:ImageLinkButton ID="btnReviewUpdate" runat="server" CommandName="Update" Visible=<%# Eval("MsgType").ToString() == "未处理" %> IsShow="false" CommandArgument='<%# Eval("FeedBackNotifyID")%>' Text="处理" /></span>
<span><Hi:ImageLinkButton ID="btnReviewDelete" runat="server" CommandName="Delete" Visible=<%# Eval("MsgType").ToString() != "未处理" %> IsShow="true" CommandArgument='<%# Eval("FeedBackNotifyID")%>' Text="删除" /></span>
--%>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Add" CommandArgument="Add" >添加</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Edit" CommandArgument="Edit">编辑</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="Update" CommandArgument="Update" OnClick="LinkButton3_Click">更新</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" runat="server" CommandName="Cancel" CommandArgument="Cancel">取消</asp:LinkButton>
<asp:LinkButton ID="LinkButton5" runat="server" CommandName="Delete" CommandArgument="Delete">删除</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
protected void LinkButton3_Click(object sender, EventArgs e)
{
//TextBox t = e.Item.FindControl("TextBox3") as TextBox;
//Label t = Page.FindControl("dtlist").Controls[1] as Label;
System.Web.UI.Page p = new System.Web.UI.Page();
TextBox t=p.FindControl("TextBox3") as TextBox;
Response.Write("<script type='text/javascript'>alert('" + t.Text + "')</script>");
//ViewState["temp"] = t.Text.ToString();
}
是因为不是page页面的控件,所以不能直接获取到吗 展开
1个回答
2016-09-14
展开全部
System.Web.UI.Page p = new System.Web.UI.Page();
这里是建立一个新的page,并不是你当前看到的page.
可以尝试下这样
datalist.FindControl("TextBox3") as TextBox;
追问
获取到的TextBox是null
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询