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!

Datagrid and drop-down menu 1

Status
Not open for further replies.

MDA

Technical User
Jan 16, 2001
243
US
Greetings, brand new to the asp.net world. I have built a simple datagrid and need to link a dropdown menu to each line. The menu will be the same for each line in the datagrid but I need to inherit information from the record to pass when the user selects one of the menu items.

With that said any help with:
1. Is it possible to create a dropdown menu inside a datagrid, if so how?

2. How do I link the record data to the menu, so I can pass.

Not sure where to start with this, any help is greatly appreciated.

Regards,
Mike
 
1. You need to put the dropdown in a template colum of the datagrid. Either in the ItemTemplate or EditItemTemplate or whichever template you want it to display in.
Create the datasource for the dropdown and the datagrid. (In my case I used a dataset.
In the Page_Load event (check if it is NOT a postback) fill any datasources (datasets etc.)
Then call datagrid.databind(). This will bind the grid and your dropdown to the datasources defined. You will see the same data in each dropdown in each row of the data grid.

2. You then need to loop throu the rows in the grid and find the value of the dropdownlist.

Dim ddlEmployee As DropDownList = CType(sender, DropDownList)
Dim dgi As DataGridItem = CType(ddlEmployee.Parent.Parent, DataGridItem)
Dim ddlClientsPerEmp As DropDownList = dgi.FindControl("ddlClientsPerEmp")

'Then you can get the selected value
'ddlEmployee.SelectedValue 'You can now use this value.
End Sub

Hope this helps...
Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top