How to set selection in dropdownlist included in a Gridview <EditItemTemplate>

W

WT

Hello,

I can figure how to set selectIndex or Value, I have tried this

<EditItemTemplate>

<asp:DropdownList ID="DDLSector3" DataSource='<%#
BindSector(this,(int)DataBinder.Eval(Container.DataItem,"wt_SectorId"))%>'
OnPreRender='SetSectorIndex' DataTextField='wt_SectorName'
DataValueField='wt_SectorId' runat="server" >

</asp:DropdownList>

</EditItemTemplate>

method BindSector returns a DataTable, it is in codebehind

but :

OnPrerender doesnt knows about the current item

BindSector(this, etc) set the page object into this, it succesfully receive
the selected index evaluated by eval, but it has no acces to the
DropDownList to select it

I have also tried to use declarative <ItemList />



Any help welcome.

CS
 
B

brian.f.oneil

I don't think PreRender is the place you want that code. Probably just
"SelectedIndex='<% SomeBindingExpression %>'".

But you may simplify all of this, or add clarity, by simply handling
the RowDataBound event of the grid in the code behind. This is
GridView, not DataGrid? I usually simply reference the dropdown in
question with something like :

"e.Row.Cells[x].Controls[x] as DropDownList"

Then set its SelectedValue or SelectedIndex based on some column in
"e.Row.DataItem"

Atleast this way you can set a breakpoint and solve problems.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top