I have a dropdownlist in gridview and bind grid view from a function in code behind for the dropdownlist.
The problem is the dropdownlist is in edittemplate and the selected value is the id in the same celle when the is dropdownlist when the row is not editing.
How I can display in editing the null value????
Add an item to your dropdownlist that represent the null value.
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("CurrencyType") %>' AppendDataBoundItems="true">
<asp:ListItem Value="">Not selected</asp:ListItem>
</asp:DropDownList>
You can put Your business logic and check whether the selected value is not null and then you can use your data items that would symbolize null when selected.
<asp:DropDownList ID="ddlitems" runat="server" SelectedValue='<%# Bind("mydata") %>' AppendDataBoundItems="true">
<asp:ListItem Value="">select</asp:ListItem>
</asp:DropDownList>
Related
I got this RadioButtonList with defined ListItems:
<asp:RadioButtonList ID="RblSpouseLocation" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="In Country" Value="0"></asp:ListItem>
<asp:ListItem Text="Outside of Country" Value="1"></asp:ListItem>
</asp:RadioButtonList>
I have a field "SpouseLocation" of type bit in my database. I need to bind the selected value of the RadioButtonList to this field.
I found tutorials of how to do it in the code-behind, but can it be done in aspx ?
I changed my database field type to int and added "SelectedValue='<%# Bind("SpouseLocation") %>" to my radiobuttonlist
The answer to this questions helped me
I have this databound radiobuttonlist in my gridview....
<asp:RadioButtonList ID="rblMyField" runat="server"
SelectedValue='<%# IIf(Eval("MyField") Is DBNull.Value, "0", Eval("MyField")) %>'
RepeatDirection="Horizontal" RepeatLayout="flow">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>
If the data is null I want nothing to be selected in the rbl. How can I do this? I know I'm close. I think. Thanks.
Set a hiddenfield on each row and set the value of that to your MyField to something not 0 or 1. Then check in behind code
<asp:HiddenField id="hiddenField" runat="server" value='<%# if(Eval("MyField") is DBNull.Value ? 2 : 0 %>' />
then loop through each row and check (getting HiddenField object with FindControl)
if(hiddenField.Value == "2") // or whatever you want to set it to
rblMyField.ClearSelection();
Am having a DropDownlist inside a repeater control.Initially the dropdown list should have the value from the database.And in my case its the userStatus property of my object.Eval and Bind is not working in this and When i use
<asp:DropDownList ID="DropDownList1" runat="server" Enabled="true" DataSource='<%#Eval("userStatus") %>' CssClass="box1" AppendDataBoundItems="true">
am getting the value of dropdown as characters.Suppose if the value is Admin its coming as A d m i n as each option.Is there any way to do it apart from the code behind page.
userStatusplease set "DataTextField" and "DataValueField" of dropdown.
<asp:DropDownList ID="DropDownList1" runat="server" Enabled="true" DataSource='<%# (string)DataBinder.Eval(Container.DataItem, "userStatus") %>' CssClass="box1" AppendDataBoundItems="true">
I Have a dropdownlist in an aspx page, I am populating the dropdownlist using a datatable. How can i apply a requiredfield validator to this dropdownlist.? Plz help me
You have to set the InitialValue for the selected item's Value that is selected first:
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="DropDownList1"
InitialValue="-- Please select --"
ErrorMessage="Please select something" />
<asp:DropDownList ID="DropDownList1" AppendDataBoundItems="true" runat="server">
<asp:ListItem>-- Please select --</asp:ListItem>
</asp:DropDownList>
I have problem with DropDownList template in Grid View, after I go in edit mode drop down have to be selected by current item instead of default value.
<asp:TemplateField HeaderText="Tour Type">
<EditItemTemplate>
<asp:DropDownList AppendDataBoundItems="true" DataSourceID="dropDownListSqlDataSource" runat="server" DataValueField="idTypetour" DataTextField="title"></asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<%#Eval("typeTitle")%>
</ItemTemplate>
</asp:TemplateField>
I tried to use SelectedValue="<%#Eval("typeTitle")%>", but has no results.
Try to use Bind instead of Eval:
SelectedValue='<%# Bind("idTypetour") %>'
The DataValueField is "idTypetour" and the DataTextField is "title", you have tried to use Eval("typeTitle"). What column is typeTitle? I assume that this must be idTypetour because you want to set the SelectedValue, what normally is the ID.
Here are informatons on the differences:
http://msdn.microsoft.com/en-us/library/ms178366.aspx