how to select blank value in ddl when datagrid goes to editmode

D

drdave

All is working well for my dropdown/datagrid except I cannot figure out
how to set my ddl selected index when the value is blank/null.


ie before edit mode the lblVariation text value is blank..

This routine sets the value strVariation

Sub dgMinimumWage_EditRow(sender as Object, e As
DataGridCommandEventArgs)
strVariation = CType(E.Item.FindControl("lblVariation"), Label).Text
dgMinimumWage.EditItemIndex = e.Item.ItemIndex
dgMinimumWageBindData()
End Sub

This routine works great when I've got a value.

Public Sub SetVariationDropDownIndex(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim ed As System.Web.UI.WebControls.DropDownList
ed = sender
If strVariation Is "" THEN
ed.SelectedIndex = 0
Else
ed.SelectedIndex = ed.Items.IndexOf(ed.Items.FindByText(strVariation))
End If
End Sub


On the html side I have this..

<asp:TemplateColumn HeaderText="Variation/Condition">
<itemtemplate>
<asp:label ID="lblVariation" Text='<%#
DataBinder.Eval(Container.DataItem, "english_text") %>' Runat="server"
/>


</ItemTemplate>

<edititemtemplate>
<asp:dropdownlist id="ddlVariations" runat="server"
DataTextField="english_text" DataValueField="minimum_wage_variation_id"
DataSource="<%# GetVariations() %>"
OnPreRender="SetVariationDropDownIndex" Width="450">
<asp:listitem Value="0">dave</asp:listitem>
</asp:dropdownlist>

</EditItemTemplate>
</asp:TemplateColumn>

However the selected value in the dropdown is always the first
variation in the datset..

Am I able to do this at runtime or maybe I should try and add a blank
value to the dataset??

Any suggestions??

Dave
 
D

David Jessee

Add a Databinding for your SelectedValue

e.g. SelectedValue='<%# String.Empty %>'
 
D

drdave

tx for the reply David but using that gives me:
Specified argument was out of the range of valid values
 

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,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top