Showing posts with label method. Show all posts
Showing posts with label method. Show all posts

Wednesday, March 21, 2012

Populating a dropdownlist

Hi Everyone,

I am trying to figure out how to populate my dropdown list with data from my table. What happens is I call a method that expects an id by using this method I want to keep looping through the recordset and populate my dropdown list with teh values I require.

Here is teh code I have attempted to write this code appears in my page load


ddlVersions.Items.Clear()

Dim _CVersion As Content = ContentManager.GetContentVersionList(Page.Request.Params("PID"))
Dim Version As Content

For Each Version In _CVersion
ddlVersions.DataTextField = "CoPgVersion"
ddlVersions.DataValueField = "CoPgID"
ddlVersions.DataBind()
Next

Here is my method


Public Shared Function GetContentVersionList(ByVal CoPgID As Integer) As Content
' Get the list of Content form the datastore
Dim _Data As SqlDataReader
Dim _Content As New Content

_Data = SqlHelper.ExecuteReader(ConfigurationSettings.AppSettings("DataStoreConnection"), CommandType.StoredProcedure, "Content_get", New SqlParameter("@dotnet.itags.org.CoPgID", CoPgID))

While _Data.Read
_Content = PopulateObjectFromSqlDataReader(_Data)
End While

_Data.Close()

Return _Content

End Function

My stored procedure is basically the following SQL Statement


Select * from content where CoPgID = @dotnet.itags.org.CoPgID

I am simply getting teh syntax wrong but I am unsure on how to correctly code the dropdownlist so it populates.

While I am here once I get the drop down list to work is there a way I can make the drop down list highlight as if selected the most current record.

Basically the dropdownlist will display all teh version of my content if I am at version 4 I want version for to appear along with the rest of teh versions but for it to be select rather than "Please Select" is this doable?

I look forward to any help one may be able to give

Kind Regards

BradHi I will try to help a bit but take it with reservation as I am just beginner using Matrix which generates code for me, but just to say that when I was populating drop down list following instructions from the matrix book I did not loop through the recordset.
Steps were:
-to create function with sql statement in it and reterning the recordset
-to assign this function to data source of drop down list so:
dropdownlist.DataSource=above function
dropdownlist.DataBind()

these 2 lines are putting your recordset in the list already but they are always within some event
for example page load event
i hope this helps
anqa
Anga is quite correct. This is the way to bind data to controls in ASP.NET.

Seethis example on LearnASP.com for more details.

Friday, March 16, 2012

Populating a DropDownList with a Data Method Code Wizard

Please help... I am sure most of you guys know the answer to this basic question

I am using the Web Matrix ...Getting Started Manual and am to the

Using a Data Method Code Wizard to Populate a DropDownList.

The question is : When asked to Remove the Button1_Click event code...

How is this done? Do I remove the entire code?? And where is the event code?

Sub Button1_Click(sender As Object, e As EventArgs)
DataList1.DataSource = GetOrderDetails(CInt(TextBox1.Text))
DataList1.DataBind()
End SubIn WebMatrix, new events are automatically hooked up to event handlers declaratively. So, after creating a method that handles a Button webcontrol's OnClick event, you'll have something like this in your HTML view:


<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>

In this example, the 'onclick' attribute's value identifies the name of the method that handles this control's Click event.

So, if you want to unhook an method from an event in Web Matrix, the simplest way to do this is to remove the corresponding event's attribute on that control's tag. What you do with the method's code after that is entirely up to you.

Hope this helps!
No..this did not help..but thanks anyway. Could you please go to the following URL and see what I mean.

http://www.asp.net/webmatrix/guidedtour/section4/ddlcodebuilder.aspx

I am 1/3 of the way through the tutorial and I like ASP.Net thus far.

Populating ComboBox From Dataset

Hi Guys,

I need to populate a combobox from a dataset returned from a webservice. I set the datasource property of the control to the web method but got an empty list at run time! What am I doing wrong? Any help on how to achieve this? Looping through a datareader solved the problem but I want to consume a dataset from a web service. I thought this would be a straight stuff but I'm having problems with it.After setting the datasource property you have to bind the data to your controll.

It seems you are missing that bit.
I can handle that with DropDownList control in ASP.Net but not with ComboBox in Windows Application! Could you kindly show how syntactically?
Are you getting an error?
What does it say?

Post your code so that we can see more clearly what has gone wrong
I am not getting any error message! I only get this wierd entry in the ComboBox. "System.Data.DataViewManagerListItemTypeDescriptor"

This is the code that I used.

Private Sub Users_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim wsDemo As New ng_app001_pc_stock.PCInventory
ComboBox1.datasource = wsDemo.getAllOSTypes
End Sub

The webmethod getAllOSTypes works well, at least I tested it with DataGrid control. What could be wrong?