2014-11-24 42 views
1

我创建了一个UserControl(带有2个文本框和1个标签)我在ListView中有这个UserControl。我有一个提交按钮,一旦触发,我想读取(2文本框和1标签)的值列表视图的每一行。我有下面的代码,但它试图读取文本框内的内容时不显示任何值。在用户控件中获取服务器控件的正确方法是什么?没有得到价值当试图从用户控件中的TetBox获取值

SpecificExperienceControl.ascx

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="SpecificExperienceControl.ascx.vb" Inherits="TardyAbsenteeReport.SpecificExperienceControl" %> 
<asp:HiddenField ID="hdnID" runat="server" /> 
<div class="SpecExp"> 
<tr> 
    <td> 
    <asp:TextBox ID="TextBox1" runat="server" CssClass="SpecExp-txtEmpID" ></asp:TextBox> 
    </td> 
    <td> 
    <asp:Label ID="Label1" runat="server" Text="Label" CssClass="SpecExp-txtLbl"></asp:Label> 
    </td> 
    <td> 
    <asp:TextBox ID="TextBox2" runat="server" CssClass="SpecExp-txtAcode"></asp:TextBox> 
</td> 
</tr> 
</div> 

SpecificExperience.aspx(用我的用户对被绑定到一个XML文件来创建25行的一个ListView空数据

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="SpecificExperience.aspx.vb" Inherits="TardyAbsenteeReport.SpecificExperience" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"> 
<script src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 
<asp:ListView ID="ListView1" runat="server"> 
<LayoutTemplate> 
    <table cellpadding="2" width="640px" border="1" runat="server" id="tblProducts"> 
     <tr id="Tr1" runat="server"> 
      <th id="Th1" runat="server">EmployeeID</th> 
      <th id="Th2" runat="server">Name</th> 
      <th id="Th3" runat="server">Absentee Code</th> 
     </tr> 
     <tr runat="server" id="itemPlaceholder" /> 
</table>   

</LayoutTemplate>      
<ItemTemplate> 
    <hr:SpecExp ID="SpecExp1" runat="server"></hr:SpecExp>  
</ItemTemplate> 
</asp:ListView> 
<div> 
    <asp:Button ID="Button1" runat="server" Text="Submit" /> 
</div> 
</asp:Content> 

SpecificExperience.aspx.vb(尝试从用户控件中的服务器控件读取数据的代码)

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 

    Dim lview As ListViewItem 

    For Each lview In ListView1.Items 

     Dim LblEmployeeName As Label = lview.FindControl("SpecExp1$Label1") 
     Dim TxtEmployeeID As TextBox = lview.FindControl("SpecExp1$TextBox1") 
     Dim TxtAbsenteeCode As TextBox = lview.FindControl("SpecExp1$TextBox2") 

     Dim StrEmployeeId As String = TxtEmployeeID.Text 
     Dim StrLblemployee As String = LblEmployeeName.Text 
     Dim StrAbsentee As String = TxtAbsenteeCode.Text 

    Next 
End Sub 

回答

0

您是否检查回发是否发生?这听起来像也许你不是,listview是每个按钮点击刚刚绑定。

+0

谢谢你是对的! – CodeEngine 2014-11-24 17:40:54