![]() |
| |||||||
| Sponsored Links |
![]() |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| ||||
| ||||
| Hi I need to populate a DataSource control with an id from a ddl, this DataSource control the populates a ddl. I have no clue how to pass the id to the DataSource control, I have tried a few things but no luck yet. my application is built on a 3 tier design, BL,BO,DA layers. I'll post the code relevant for the DataSource control i'm trying to populate. DA: (in my DA i also have a class that holds my querystrings) the query: Code: Public Class QueryZonesDB
Public Shared strSQL
Public Shared Function Zones(ByVal pid As Integer)
strSQL = "SELECT "
strSQL = strSQL & "idkey, "
strSQL = strSQL & "project_id, "
strSQL = strSQL & "userID, "
strSQL = strSQL & "edited, "
strSQL = strSQL & "name, "
strSQL = strSQL & "description "
strSQL = strSQL & "FROM tblzones "
strSQL = strSQL & "WHERE idkey = " & pid & " "
strSQL = strSQL & "ORDER BY name ASC"
Return strSQL
End Function
Code: Public Class ZonesDB
Public Shared Function GetList(ByVal id As Integer) As ZonesList
Dim tempList As ZonesList = Nothing
'Using
Dim myConnection As MySqlConnection = New MySqlConnection(myConfig.myConnection)
Try
Dim myCommand = New MySqlCommand(QueryZonesDB.Zones(id), myConnection)
myConnection.Open()
' Using
Dim myReader As MySqlDataReader = myCommand.ExecuteReader
Try
If myReader.HasRows Then
tempList = New ZonesList
While myReader.Read
tempList.Add(FillDataRecord(myReader))
End While
End If
myReader.Close()
Finally
CType(myReader, IDisposable).Dispose()
End Try
Finally
CType(myConnection, IDisposable).Dispose()
End Try
Return tempList
End Function
Private Shared Function FillDataRecord(ByVal myDataRecord As IDataRecord) As Zones
Dim myZones As Zones = New Zones
myZones.Idkey = myDataRecord.GetInt32(myDataRecord.GetOrdinal("idkey"))
myZones.ProjectID = myDataRecord.GetInt32(myDataRecord.GetOrdinal("project_id"))
myZones.UserID = myDataRecord.GetInt32(myDataRecord.GetOrdinal("userID"))
myZones.Edited = myDataRecord.GetInt32(myDataRecord.GetOrdinal("edited"))
myZones.Name = myDataRecord.GetString(myDataRecord.GetOrdinal("name"))
myZones.Description = myDataRecord.GetString(myDataRecord.GetOrdinal("description"))
Return myZones
End Function
Code: Public Class Zones
Private _idkey As Nullable(Of Integer)
Private _project_id As Nullable(Of Integer)
Private _user_id As Nullable(Of Integer)
Private _edited_id As Nullable(Of Integer)
Private _name As String = String.Empty
Private _description As String = String.Empty
<DataObjectFieldAttribute(True, True, False)> _
Public Property Idkey() As Integer
Get
Return _idkey
End Get
Set(ByVal value As Integer)
_idkey = value
End Set
End Property
Public Property ProjectID() As Integer
Get
Return _project_id
End Get
Set(ByVal value As Integer)
_project_id = value
End Set
End Property
Public Property UserID() As Integer
Get
Return _user_id
End Get
Set(ByVal value As Integer)
_user_id = value
End Set
End Property
Public Property Edited() As Integer
Get
Return _edited_id
End Get
Set(ByVal value As Integer)
_edited_id = value
End Set
End Property
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Property Description() As String
Get
Return _description
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
End Class
Code: Public Class ZonesList
Inherits List(Of Zones)
Public Sub New()
End Sub
End Class
Code: Public Class ZonesManager
<DataObjectMethod(DataObjectMethodType.Select, True)> _
Public Shared Function GetList(ByVal id As Integer) As ZonesList
Return ZonesDB.GetList(id)
End Function
Code: <form id="form1" runat="server">
<div>
<p>
<asp:Label ID="lblWelcome" runat="server"></asp:Label> |
<asp:HyperLink ID="logout" runat="server" NavigateUrl="~/Default.aspx">LogOut</asp:HyperLink>
</p>
</div>
<div>
<p>
<asp:DropDownList ID="ProjectDDL" runat="server" AutoPostBack="True" DataSourceID="ProjectDataSource"
DataTextField="Name" DataValueField="Idkey">
</asp:DropDownList>
<asp:ObjectDataSource
ID="ProjectDataSource"
runat="server"
DataObjectTypeName="Keith.ProjectManager.BO.Projects"
DeleteMethod="Delete"
InsertMethod="Save"
SelectMethod="GetList"
UpdateMethod="Update"
TypeName="Keith.ProjectManager.Bll.ProjectsManager">
<SelectParameters>
<asp:Parameter Name="id" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</p>
</div>
<div>
<p>
<asp:Label ID="textmsg" runat="server"></asp:Label>
<asp:DropDownList ID="ZonesDDL" runat="server" AutoPostBack="True" DataSourceID="ZonesDataSource"
DataTextField="Name" DataValueField="Idkey" Visible="False">
<asp:ListItem>Select Here</asp:ListItem>
</asp:DropDownList>
<asp:ObjectDataSource
ID="ZonesDataSource"
runat="server"
DataObjectTypeName="Keith.ProjectManager.BO.Zones"
DeleteMethod="Delete"
InsertMethod="Save"
SelectMethod="GetList"
TypeName="Keith.ProjectManager.Bll.ZonesManager"
UpdateMethod="Update">
<SelectParameters>
<asp:Parameter Name="id" />
</SelectParameters>
</asp:ObjectDataSource>
</p>
</div>
</form>
![]() thanks Shem |
| Sponsored Links |
|
#3
| ||||
| ||||
| exacto ![]() |
|
#4
| ||||
| ||||
| Try changing this:- Code: <SelectParameters>
<asp:Parameter Name="id" />
</SelectParameters>
Code: <SelectParameters>
<asp:ControlParameter Name="id" ControlID="ProjectDDL" />
</SelectParameters>
|
|
#5
| ||||
| ||||
| tried that already no luck |
|
#6
| ||||
| ||||
| is there a way that we can check if the ProjectDDL.SelectedValue is being passed to ZonesDataSource? Shem |
|
#7
| ||||
| ||||
| What actually happens when you try the change I posted? Do you get any errors? Does the DDL just not get populated? As far as I know that is the correct way to pass an id to datasource control. I don't use datasource controls so am guessing a little bit here. |
|
#8
| ||||
| ||||
| did a response.write on: Code: Public Shared Function Zones(ByVal pid As Integer)
strSQL = "SELECT "
strSQL = strSQL & "idkey, "
strSQL = strSQL & "project_id, "
strSQL = strSQL & "userID, "
strSQL = strSQL & "edited, "
strSQL = strSQL & "name, "
strSQL = strSQL & "description "
strSQL = strSQL & "FROM tblzones "
strSQL = strSQL & "WHERE idkey = " & pid & " "
strSQL = strSQL & "ORDER BY name ASC"
HttpContext.Current.Response.Write(strSQL)
Return strSQL
End Function
so how come my ZonesDDL is blank ![]() Shem |
|
#9
| ||||
| ||||
| My guess is an error in your GetList function. I add an error catching property to my BO classes to pass an errors to. Try using a catch ex as exception in the try in your GetList function to catch any error that it's generating. Should be something like Code: Try . . . Catch ex as Exception templist = New ZonesList templist.page_error = ex.tostring finally . . end try Something like templist.add(ex.tostring)</edit> <edit2>Actually, that wouldn't work either as the list would be expecting a Zones type, not a string...Hmmm...Tricky....Will have to have a think</edit2> I said this ages ago, but I do sometimes find .NET a bit like using Dreamweaver, in that it puts all the code together for you and if it doesn't work as you anticipate it's a devil's own job to work out why... Last edited by richyrich; June 30th, 2008 at 05:44 AM. |
|
#10
| ||||
| ||||
| ok it's getting values but as you can see below, the option name is blank? Code: <select name="ZonesDDL" onchange="javascript:setTimeout('__doPostBack(\'ZonesDDL\',\'\')', 0)" id="ZonesDDL">
<option value="4"></option>
<option value="5"></option>
<option value="6"></option>
</select>
@RR: what do you use if ya don't use datasource control? |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| populate combobox from another | Jaykappy | Microsoft Access | 4 | May 7th, 2008 02:56 PM |
| WebCharts Control | richyrich | .Net Development | 1 | April 4th, 2008 11:14 AM |