cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping ID in dropdown

Former Member
0 Kudos

Hi all!

Using PDK.NET 2.0 and MS VS2003.

I am returning two fields from a SQL-select, ID and Name.

In a dropdown I want just the name to show, not the ID. But I still want the name to be connected to the correct ID in my database.

Is this possible?

Regards,

Simon

PS: this is urgent!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Simon,

You would do this the same way you would in a regular ASP.NET Web Form.

I would recommend you not use the SAP Netweaver DropDownByKey, but use the standard ASP.NET DropdownList control for the sake of simplicity. Be sure and apply the same styles to the control though as aesthetic consistency is important in the Portal. You can then learn the DropDownByKey control later (since you say this is urgent).

Here is an example:

IDataReader dr = //Your reader goes here.

while (dr.Read())
{
	ListItem newListItem =  new ListItem();
//This would be the description field in your SQL query. 
	newListItem.Text = dr.GetString(1);
//This would be the value field in your SQL query.
	newListItem.Value = dr.GetString(0); 
	myDdl.Items.Add(newListItem); 
}
myDdl.Items.Add(newList);
myDdl.SelectedIndex = myDdl.Items.Count-1;

Former Member
0 Kudos

Hi Shibli,

thanks for the help, but I need it to be sap control.

btw I am using stored procedure and designer for the database connection.

Simon

Former Member
0 Kudos

Thanks to your help i managed to connect with sap dropdown control:


sqlConnection1.Open();
			IDataReader dr = this.sqlSelectCommand2.ExecuteReader();
while (dr.Read())
			{
				SAP.Web.UI.Controls.DropDownListItem newListItem = new SAP.Web.UI.Controls.DropDownListItem();
				//This would be the description field in your SQL query.
				newListItem.Text = dr.GetString(1);
				//This would be the value field in your SQL query.
				newListItem.Key = dr.GetInt32(0).ToString();
				DropDownByKey1.Items.Add(newListItem);	
			}
			sqlConnection1.Close();

Printed the code in case anyone else needs it.

Simon

Answers (0)