无法访问嵌套列表视图中的控件 [英] Unable to access controls in nested listview
问题描述
我有一个listview控件,它按照我想要的方式运行。
I have a listview control that functions the way I want it to.
- 一个按钮,可以切换 的可见性;表格行。
- 点击标题按列排序列表视图。
- a button that will toggle the visibility of a table row.
- clicking on the header sorts the listview by that column.
每列的定义如下:
"------------------------------------------------- -----------------------------------
< th id = " Th3的" runat =" server">
< asp:LinkButton runat =" server" ID = QUOT; sortJobName"
Text =" Job Name"的CommandName = QUOT;排序和QUOT; CommandArgument = QUOT; JOB_NAME"的CssClass = QUOT按钮"宽度=" 200px" />
< / th>
'----------------- -------------------------------------------------- -----------------
按钮是这样定义的
each column is defined like the following
'------------------------------------------------------------------------------------
<th id="Th3" runat="server">
<asp:LinkButton runat="server" ID="sortJobName"
Text="Job Name" CommandName="Sort" CommandArgument="Job_Name" cssClass="button" Width="200px"/>
</th>
'------------------------------------------------------------------------------------
the button is defined this way
'----------------------------------------------- -------------------------------------
< td> ;
< asp:Button ID =" Hide1" RUNAT = QUOT;服务器" CommandArgument ='<%#Eval(" JobID")%>'CommandName ="隐藏"文本= QUOT + QUOT;&NBSP; />
$
< asp:Label ID =" HistoryDateLabel" RUNAT = QUOT;服务器" Text ='<%#Format(Eval(" History_Date")," Short Date")%>'/>&
< / td>
'---------------------------------------------- --------------------------------------
我将此控件嵌套在另一个listveiw中,并将数据库更改为在Page_Load事件中创建的数据集。
'------------------------------------------------------------------------------------
<td>
<asp:Button ID="Hide1" runat="server" CommandArgument='<%# Eval("JobID")%>' CommandName="Hide" Text="+" />
<asp:Label ID="HistoryDateLabel" runat="server" Text='<%# Format(Eval("History_Date"), "Short Date")%>' />
</td>
'------------------------------------------------------------------------------------
I nested this control in another listveiw and changed the datasourse to a dataset that is created in the Page_Load event.
'---------- -------------------------------------------------- ------------------------
Dim dsOpen As New DataSet()
  ; Dim dataOpen As SqlDataAdapter = New SqlDataAdapter
Dim strConn As String =""
Dim strSQL As String =" exec prcJob;"
暗淡sqlConn作为SqlConnection的
'------------------------------------------------------------------------------------
Dim dsOpen As New DataSet()
Dim dataOpen As SqlDataAdapter = New SqlDataAdapter
Dim strConn As String = ""
Dim strSQL As String = "exec prcJob;"
Dim sqlConn As SqlConnection
&NBSP; sqlConn =新的SqlConnection(创建失败)
&NBSP; dataOpen =新的SqlDataAdapter(STRSQL,sqlConn)
dataOpen.TableMappings.Add(" Category"," Category")
dataOpen.TableMappings.Add(" Category1"," JobTracking")
sqlConn = New SqlConnection(strConn)
dataOpen = New SqlDataAdapter(strSQL, sqlConn)
dataOpen.TableMappings.Add("Category", "Category")
dataOpen.TableMappings.Add("Category1", "JobTracking")
dataOpen.Fill(dsOpen," Category")
dsOpen.Relations.Add(" CatRel",dsOpen.Tables(" Category"))。列("分类"),dsOpen.Tables(QUOT; JobTracking")。柱("分类"))
&NBSP; dsOpen.Relations(0).Nested =真
dataOpen.Fill(dsOpen, "Category")
dsOpen.Relations.Add("CatRel", dsOpen.Tables("Category").Columns("Category"), dsOpen.Tables("JobTracking").Columns("Category"))
dsOpen.Relations(0).Nested = True
&NBSP;昏暗myListView作为ListView的
&NBSP; myListView =的FindControl(QUOT; OpenJobs")
&NBSP; myListView.DataSource = dsOpen.Tables( " Category")
'------------------------------------ ------------------------------------------------
Dim myListView As ListView
myListView = FindControl("OpenJobs")
myListView.DataSource = dsOpen.Tables("Category")
'------------------------------------------------------------------------------------
新页面显示外部列表视图和作业中的类别名称s与内部
列表视图中的类别相关联。此时,排序功能或按钮单击都不再起作用。所以我添加了代码以在类别列表视图的ItemDataBound事件中添加事件处理程序
。
The new page displayes the Category Name in the outer listview and the jobs associated with the category in the inner
listview. At this point neither the sort funtion or the button click work anymore. so I added code to add an event handler
in the ItemDataBound event of the Categories listview.
'------------ -------------------------------------------------- ----------------------
Dim LV作为ListView = CType(e.Item.FindControl(" Jobs"),ListView)
AddHandler LV.ItemCommand,AddressOf OpenJobs_ItemCommand
'---------------------------------- --------------------------------------------------
处理程序正确触发,因为我看到它在外部listveiw中为每个类别执行。当我点击按钮时,我看到它通过OpenJobs_ItemCommand sub。但是我似乎无法改变数据行的可见性。
我在某处读到了我必须更改底层数据才能显示在列表视图中。所以我在
的数据集中添加了一列来控制可见性。默认设置为0或者可见='False'。
'------------------------------------------------------------------------------------
Dim LV As ListView = CType(e.Item.FindControl("Jobs"), ListView)
AddHandler LV.ItemCommand, AddressOf OpenJobs_ItemCommand
'------------------------------------------------------------------------------------
The handler triggers correctly because i see it executed for each category in the outer listveiw. And when I click the button, I see it step through OpenJobs_ItemCommand sub. However I don't seem to be able to change the visibility of the datarow.
I read somewhere that I have to change the underlying data for it to show up in the listview. So I added a column to
the dataset to control the visibility. The default is set to 0 or visible='False'.
'------------------------- -------------------------------------------------- ---------
visible ='<%#Eval(" ShowHistory")%>'¥b $ b'---- -------------------------------------------------- ------------------------------
'------------------------------------------------------------------------------------
visible='<%# Eval("ShowHistory")%>'
'------------------------------------------------------------------------------------
我可以在Page_Load中成功地解决这个问题通过将特定行设置为1
I can toggel this successfully in the Page_Load sub by setting a specific row to 1
'------------------------------ -------------------------------------------------- ----
$
dsOpen.Tables(" JobTracking")。行(4).Item(" ShowHistory")= 1
'--- -------------------------------------------------- -------------------------------
但是我似乎无法在ItemCommand子中执行此操作。跟踪表明它正在找到正确的行,而
数据集中的值被设置为1.
'------------------------------------------------------------------------------------
dsOpen.Tables("JobTracking").Rows(4).Item("ShowHistory") = 1
'------------------------------------------------------------------------------------
But I can't seem to be able to do this in the ItemCommand sub. A trace indicates that it is finding the correct row and
the value in the dataset is being set to 1.
'-------- -------------------------------------------------- --------------------------
$
子OpenJobs_ItemCommand(BYVAL发件人为ListView中,BYVALË作为ListViewCommandEventArgs)
'------------------------------------------------------------------------------------
Sub OpenJobs_ItemCommand(ByVal sender As ListView, ByVal e As ListViewCommandEventArgs)
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Dim myListView As ListView = sender
Dim myListView As ListView = sender
如果e.CommandName =" Hide"然后
If e.CommandName = "Hide" Then
Dim txtSearch As String =" RequestId =" + e.CommandArgument.ToString
对于每行中dsOpen.Tables(QUOT; JobTracking")。选择(txtSearch)
Dim txtSearch As String = "RequestId=" + e.CommandArgument.ToString
For Each row In dsOpen.Tables("JobTracking").Select(txtSearch)
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP; row.Item(QUOT; ShowHistory")= 1个
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; row.AcceptChanges()
row.Item("ShowHistory") = 1
row.AcceptChanges()
下一个
myListView.DataBind()
结束如果
Next
myListView.DataBind()
End If
结束点¥
'--------------------------------------- ---------------------------------------------&NBSP;&NBSP;&NBSP ;
End Sub
'------------------------------------------------------------------------------------
我尝试了很多东西,包括底层数据集的数据绑定。到目前为止,没有任何工作。
I've tried a number of things including a databind of the underlying dataset. So far nothing has worked.
排序功能也破裂了。如果我尝试使用默认值,我会收到一个错误:ListView'JOBS'引发的事件排序未处理。
我添加一个像ItemCommand Handler这样的处理程序后,我得到一个堆栈溢出例外。
The sorting function broke too. If I try to use the defaults, I get an error: The ListView 'JOBS' raised event Sorting which wasn't handled.
After I add a handler like the ItemCommand Handler, I get a stack overflow exception.
'---------------------------------- -------------------------------------------------- &NBSP;&NBSP;&NBSP;
AddHandler LV.Sorting,AddressOf OpenJobs_Sorting
'------------------------------------------------------------------------------------
AddHandler LV.Sorting, AddressOf OpenJobs_Sorting
'------------------------------- -------------------------------------------------- ---&NBSP;&NBSP;&NBSP;
Sub OpenJobs_Sorting(ByVal sender As ListView,ByVal e As ListViewSortEventArgs)
sender.Sort(e.SortExpression,e.SortDirection)
'------------------------------------------------------------------------------------
Sub OpenJobs_Sorting(ByVal sender As ListView, ByVal e As ListViewSortEventArgs)
sender.Sort(e.SortExpression, e.SortDirection)
结束点¥
'--------------------------------------- ---------------------------------------------&NBSP;&NBSP;&NBSP ;
End Sub
'------------------------------------------------------------------------------------
我没有复制整个代码,因为它非常大。我希望你在这里已经足够了,有人可能会看到我做错了什么。
I didn't copy the entire code because it is quite large. I hope thee is enough here that someone might be able to see what I'm doing wrong.
Jo Lee
推荐答案
感谢详细的帖子Jo,但我担心这不是ASP.Net WebForms应用程序的正确论坛。 由于您的问题特定于Web控件数据绑定,因此您可能会从ASP.Net论坛获得更好的响应。
Thanks for the detailed post Jo, but I'm afraid this isn't the correct forum for ASP.Net WebForms applications. Since your issue is specific to web control databinding you'll likely get better responses from the ASP.Net forums.
这篇关于无法访问嵌套列表视图中的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!