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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding database values in ItemDataBound of a dg 1

Status
Not open for further replies.

Billkamm

Programmer
Feb 9, 2006
74
US
I have a datagrid where when you click the edit button dropdownlists appear for that row. However, I need a way to change the dropdownlist to the appropriate value (it always starts at the top). Does anyone know the syntax as to how I would obtain this value, so that I can update the dropdownlist?

Do I have to requery the database or is there a way to get the value from e As System.Web.UI.WebControls.DataGridItemEventArgs?
 
What I usually do is to have the values i want to find in the ddl in a column(s) in the datagrid. If you don't want them to be seen, make those columns visible=FALSE. Then I find the value and do a ddl.FindByValue("val").selected = TRUE to set the ddl.

Jim
 
That solution would work, but I was hoping there was another way such as using dgDataGridName.DataSource or something coming off of "e".

If anyone knows a better please let me know.
 
That works for all the rows except the ones where I have dropdownlists (the edit row)
 
you have to find the control

dim ddl as new dropdownlist
ddl = e.Item.FindControl("yourddl")
 
Thanks, I actually just found out that my problem was I had hidden column in slot 0, so I was pulling the wrong value because of that and that was my problem. e.Item.DataItem works to get the row of information I need.
 
I actually tried this to change the value:

CType(e.Item.Cells(1).Controls(1), DropDownList).Items.FindByText(strPostalAbbreviation).Selected = True

but that doesn't work because it says "Object reference not set to an instance of an object. " Do you have any ideas?
 
I found out my problem was I was using Cells(1) instead of Cells(0), so I was referring to the wrong control.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top