2014-11-24 47 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