Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataBinder.Eval for WebForm in VisualStudio.Net

Status
Not open for further replies.

JGresko

Programmer
Apr 24, 2002
86
US
I've used ASP and VB, but I'm am a Nubie to .NET and am having trouble using Web Forms controls. If I write an .aspx page by hand, I can get it working... everything displays and the dropdowns fill with correct data from my database (Oracle). My problem is that when I try to use Web Forms controls (ie the dropdown listbox), I can't get the data to populate at all.

I've configured a OleDbDataAdapter and generated the DataSet. I can preview the data in the dataset and it's correct, but when I build the project and try to view the page, the drop down list is empty...

Can anyone point me in the right direction?

Thanks,

Judy
 
I used a datareader to create a ListItemCollection object, and then I have assigned the DataSource of the DropDownList to the ListItemCollection object.

The problem is that you need to pass the right ID to the DropDownList in the EditItemTemplate to select the right Item. I did that through a little function that is being called in the ItemCreated event of the DataGrid.

I hope this puts you in the right direction, if you need further help just let me know.

 
Thanks Alcar,

I'm not famililar with EditItemTemplate, but your suggestion sounds similar to the method I used when I wrote it out without using the Visual Studio Web Forms Controls. The code I used that works is below, but I'm still trying to get the Web Forms Controls to work with DataAdapters and DataSets like the samples tell me they should.

Thanks for the fast reply!

Code:
Dim strConn As String = "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=muID;password=myPswrdt;Data Source=QS;"

Dim Conn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(strConn)

Dim strSQL As String = "SELECT DISTINCT CODTYP AS Value, LIBTGB AS ""Type"" FROM TABTYP ORDER BY 2"

Dim Cmd As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand(strSQL, Conn)

Conn.Open()

lstType.DataSource = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

lstType.DataBind()

Conn.Close()
 
in c# you would have to do this:

sqlDataReader dr;
oCmd.Connection.Open(); // open the connection to the DataBase
dr = oCmd.ExecuteReader(); // Execute the Command Object and fill the DataReader
ddlMyDropDownList.Items.Clear(); // clear all the items contained in the DropDownList

while(dr.Read()) // while there is a row to read
{
ListItem oItem = new ListItem(); // Create a new ListItem Object used to fill the DropDownList Control
oItem.Value = dr["field1"].ToString(); // Assign the ListItem Value equals to the "field1" field
oItem.Text = dr["field2"].ToString(); // Assign the ListItem Text equals to the "field2" field
ddlMyDropDownList.Items.Add(oItem); // add the ListItem to the DropDownList Control
}

while in vb.net it should be:

Dim dr As sqlDataReader

oCmd.Connection.Open() // open the connection to the DataBase
dr = oCmd.ExecuteReader() // Execute the Command Object and fill the DataReader
ddlMyDropDownList.Items.Clear() // clear all the items contained in the DropDownList

while dr.Read // while there is a row to read

Dim oItem As ListItem = New ListItem() // Create a new ListItem Object used to fill the DropDownList Control
oItem.Value = dr("field1").ToString() // Assign the ListItem Value equals to the "field1" field
oItem.Text = dr("field2").ToString() // Assign the ListItem Text equals to the "field2" field
ddlMyDropDownList.Items.Add(oItem) // add the ListItem to the DropDownList Control

end while

** check the vb.net syntax, I'm kind of rusty on that side =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top