dropdownlist in a datagrid - allow for no value to be selected

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I'm using TemplateColumns in a datagrid to allow a record to be edited. The
record contains several columns that are dropdownlists that pull from
"dictionary/ code-decode" tables. However, these columns are NOT required
in the underlying table. Given that I'm using TemplateColumns, what is the
best way to allow a user to leave the drop down list unselected? Or is
there another approach I should be taking?

Thanks in advance!
Mark

<asp:TemplateColumn HeaderText="Rank">
<ItemTemplate>
<asp:Label id="lblRank" Text='<%# DataBinder.Eval(Container,
"DataItem.rank_descr")%>' Runat="server"/>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlrank" Runat="server" DataValueField="rank_cd"
DataTextField="rank_descr" DataMember="rank_cd" DataSource="<%#
GetRankTable() %>"/>
</EditItemTemplate>
</asp:TemplateColumn>
 
There may be better ways, but what I have done is insert an item at the
beginning of the dropdownlist. Something like "(Select)". If they haven't
selected anything, the selected index will point to the placeholder
"(Select)" item. Then in the code-behind when I am looking for changes, I
just look to see if they have picked something other than the placeholder.
 
Back
Top