我试图重新审视此问题,因为我似乎找不到答案。我创建了一个用户控件,当我在Parent_ID中进行硬编码时,它可以很好地工作。但是,我想根据GridView的行中的值动态分配Parent_ID。
这是用户控件的代码背后:
Public Class Comments
Inherits System.Web.UI.UserControl
Public _name As String
<System.ComponentModel.Bindable(True), System.ComponentModel.Browsable(True)> _
Public Property Parent_ID() As String
Get
Return _name
End Get
Set(value As String)
_name = value
End Set
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
If Parent_ID Is Nothing Then Parent_ID = "-1"
DataSource_Comments.FilterParameters(0).DefaultValue = Parent_ID
'lbl_Parent_Alert.Text = "Parent_ID: " & Parent_ID
End If
End Sub
End Class
ASP.net aspx页面:
<%@ Page Title="About Us" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
CodeBehind="About.aspx.vb" Inherits="MOO.About" %>
<%@ Register TagPrefix="uc" TagName="Comments_Control" Src="~/Comments.ascx" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:SqlDataSource ID="DataSource_Missed_Yesterday" runat="server"
ConnectionString="<%$ ConnectionStrings:MainMOOConnectionString %>"
SelectCommand="SELECT * FROM func_Missed_Yesterday() Order By Total_Price DESC"
>
</asp:SqlDataSource>
<asp:GridView ID="GV_Missed_Yesterday" runat="server" DataSourceID="DataSource_Missed_Yesterday"
AutoGenerateColumns="false" CssClass="Grid_View">
<Columns>
<asp:BoundField DataField="num_Order_Num" HeaderText="Order Number"/>
<asp:BoundField DataField="mem_Order_Notes" HeaderText="Order Notes"/>
<asp:TemplateField HeaderText="Order Notes">
<ItemTemplate>
<asp:Label ID ='lbl' runat="server" text='<%#Eval("num_Order_Num") %>'/>
<uc:Comments_Control id="Comments_Control_ID" runat="server" Parent_ID='<%#Eval("num_Order_Num") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Content>
Aspx.vb页面:
Imports System.Data
Public Class About
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Sub GV_Missed_Yesterday_DataBound(sender As Object, e As GridViewRowEventArgs) Handles GV_Missed_Yesterday.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
End If
End Sub
End Class
同样,如果我对这一行进行硬编码:
<uc:Comments_Control id="Comments_Control_ID" runat="server" Parent_ID='<%#Eval("num_Order_Num") %>' />
如:
<uc:Comments_Control id="Comments_Control_ID" runat="server" Parent_ID='1162519' />
我看到有关订单1162519的适当注释。当我将其保留为Eval(“ num_Order_Num”)时,我什么也没得到。
我预先感谢您指出正确的方向。
谢谢,
罗伯
我可能是错的,但是我认为首先要创建模板中的控件(此时,Page_Load
事件处理程序将在用户控件中运行),然后对所有绑定语言表达式进行求值。因此,通过Parent_ID
在用户控件的Page_Load
例程中测试的值,您就太早发现了它。
尝试使用PreRender
事件而不是Load
事件来测试Parent_ID
值。该操作将在渲染之前执行,并在评估任何绑定表达式之后执行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句