使用SQLDataSource对象进行故障

时间:2009-08-10 06:28:38

标签: asp.net data-binding user-controls

现在我知道为什么我只使用MySQL和未绑定的对象...这个SQLDataSource的东西是为鸟类...反正,因为我将它用于我的项目,我有带有转发器的.ascx用户控件,该转发器连接到SQLDataSource对象。我正在尝试根据父页面上下拉框中的选择动态传入参数。但是,我无法从下拉框中提取值,因为用户控件首先绑定!如何从下拉列表中获取值后,如何让用户控制绑定?

感谢

编辑:这里是一些代码。我是这个整个数据绑定对象的新手,所以请温柔:)

父网页HTML

<asp:dropdownlist runat="server" id="ddUsers" autopostback="true"
 datasourceid="sqlUsers" datatextfield="username" datavaluefield="userid" />
<asp:sqldatasource runat="server" id="sqlUsers" 
 selectcommand="SELECT * FROM [users]" connectionstring="<%$ 
 ConnectionStrings:ConnectionString %>" />

....
<div id="gallery">
    <ul>
        <pa:photolist runat="server" id="plGallery" albumid="0" />
    </ul>
</div>
....

父页面代码隐藏

Private Sub ddUsers_DataBound(ByVal sender As Object,
 ByVal e As System.EventArgs) Handles ddUsers.DataBound
    Dim id As Integer = ddUsers.SelectedValue
End Sub

UC HTML

<asp:repeater runat="server" id="rPhotos" datasourceid="sqlPhotos">
    <itemtemplate>
      Stuff
    </itemtemplate>
</asp:repeater>
<asp:sqldatasource runat="server" id="sqlPhotos"
 selectcommand='SELECT * FROM PhotosWithTags 
  WHERE userid=@userid AND albumid=@albumid'
 connectionstring="<%$ ConnectionStrings:ConnectionString %>" >
    <selectparameters>
         <asp:parameter name="albumid" defaultvalue="0" />
         <asp:parameter name="userid" defaultvalue="1" />
    </selectparameters>
</asp:sqldatasource>

UC Codebehind

Partial Public Class photolist : Inherits System.Web.UI.UserControl
Private _albumid As Integer
Public Property AlbumID() As Integer
    Get
        Return _albumid
    End Get
    Set(ByVal value As Integer)
        _albumid = value
    End Set
End Property
Private _userid As Integer
Public Property UserID() As Integer
    Get
        Return _userid
    End Get
    Set(ByVal value As Integer)
        _userid = value
    End Set
End Property
Protected Sub Page_Load(ByVal sender As Object, 
ByVal e As System.EventArgs) Handles Me.Load
    sqlPhotos.SelectParameters("userid").DefaultValue = UserID
    sqlPhotos.SelectParameters("albumid").DefaultValue = AlbumID
End Sub
End Class

仍然有这个问题:\任何人有任何想法?感谢...

0 个答案:

没有答案