I'm programming a website in asp.net c# which contain a dropdownlist inside the GridView, of this nature.
Please find the below code for more information.
<asp:TemplateField HeaderText="blahblah">
<ItemTemplate>
<asp:DropDownList runat="server" ID="placeID" CssClass="ddlPlaceID">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
[...]
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
The problem is, the list does not drop down when pressed on an iPad/iPhone device. It works mighty fine on a desktop however. I'm quite the rookie with asp.net, so I am sure that the answer is why it doesn't work is obvious.
Related
I am looking to fill a dropdownlist within a gridview with manual data. Is there anyway to do this through the markup code? I am just trying to fill it with days etc. 1 day(s), 2 day(s), 3 day(s) etc. Here is the code for my drop down
<asp:TemplateField HeaderText="No. Days">
<ItemTemplate>
<asp:DropDownList ID="txtFinishDate" runat="server"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
I've tried filling it manually on the page load but it doesn't seem to work and I think it is because of the grid view. Sorry if the question seems vague and thanks in advance!
what you have, but you have to add items to the list.
<asp:TemplateField HeaderText="custom">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="[ select an item ]" Value="0"></asp:ListItem>
<asp:ListItem Text="yes?" Value="1"></asp:ListItem>
<asp:ListItem Text="no?" Value="2"></asp:ListItem>
<asp:ListItem Text="umm..." Value="3"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
I have a following code in aspx page
<asp:DropDownList ID="txtSupplierCountry" class="form-control" Width="230px" runat="server">
<asp:ListItem Text="Select gender" Value="0"></asp:ListItem>
<asp:ListItem Text="male" Value="0"></asp:ListItem>
<asp:ListItem Text="female" Value="1"></asp:ListItem>
</asp:DropDownList>
I have a value in database as male/female. I need to set this text using C# code. Basically I am trying to set selected option based on the text from database. I am not getting an idea. I have tried following code but it doesn't work.
String t = "male" // coming from db
txtSupplierCountry.Items.FindByText(t).Selected = true;
when you are saving data Male and Female then why did you keep dropdown values in number like 1,2 etc, change code like this.
<asp:DropDownList ID="txtSupplierCountry" class="form-control" Width="230px" runat="server">
<asp:ListItem Text="Select Country" Value="0"></asp:ListItem>
<asp:ListItem Text="male" Value="male"></asp:ListItem>
<asp:ListItem Text="female" Value="female"></asp:ListItem>
then
txtSupplierCountry.SelectedValue="male";
I am working on an ASP.Net application with code behind as C#. In an aspx page, there is a gridview control. One column contains dropdownlist, as follows:
<asp:GridView ID="gvModulesSem1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Grade" HeaderStyle-HorizontalAlign="Left" HeaderStyle-CssClass="gvModulesTextPadding">
<ItemStyle Width="120px" CSSClass="gvModulesTextPadding" />
<ItemTemplate>
<asp:DropDownList ID="ddlSelectGrade" Text='<%# Eval("Grade")%>' runat="server">
<asp:ListItem Value="-1.0">Select Grade</asp:ListItem>
<asp:ListItem Value="Distinction">Distinction</asp:ListItem>
<asp:ListItem Value="A">A</asp:ListItem>
<asp:ListItem Value="B+">B+</asp:ListItem>
<asp:ListItem Value="B">B</asp:ListItem>
<asp:ListItem Value="C+">C+</asp:ListItem>
<asp:ListItem Value="C">C</asp:ListItem>
<asp:ListItem Value="D+">D+</asp:ListItem>
<asp:ListItem Value="D">D</asp:ListItem>
<asp:ListItem Value="P">P</asp:ListItem>
<asp:ListItem Value="F">F</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
There are some other columns too, all of which contain labels. But, to keep it simple, I have removed the codes for the other columns.
In page load, when Page.IsPostBack is false, the GridView is bound to a DataTable (which has been filled). This populates the GridView. All the DropDownLists have the first item i.e. "Select Grade" selected.
As a user, I change the selected items of the dropdown lists. Then click a button (outside the grid). In the button click event procedure, when I try to read the selected item of any dropdown list, I find that it is always the first item.
How do I correct this problem?
Thank you.
To be brief, I need the Textbox with ID="textComments" to only appear when the dropdown option of 'Other' is selected from the dropdown, and then disappear if another selection is made. I could do this with JS but it needs to be in C#.
<asp:DropDownList runat="server" ID="dropEnquiryType" CssClass="dropdownRequestList">
<asp:ListItem Value="Customer Services" Text="Customer Services"></asp:ListItem>
<asp:ListItem Value="Website" Text="Website"></asp:ListItem>
<asp:ListItem Value="Contract" Text="Contract Hire"></asp:ListItem>
<asp:ListItem Value="Other" Text="Other"></asp:ListItem>
</asp:DropDownList>
<asp:label runat="server" ID="lblComments" AssociatedControlID="textComments" CssClass="textLabel">Comments:</asp:label>
<asp:TextBox runat="server" MaxLength="200" TextMode="MultiLine" Columns="40" Rows="4" ID="textComments" Wrap="true" CssClass="textComments"></asp:TextBox>
And help would be greatly appreciated.
Make the DropDownList first AutoPostBack=true
handle it's SelectedIndexChanged-event
Switch visibility of both controls there
aspx:
<asp:DropDownList AutoPostBack="true" OnSelectedIndexChanged="dropEnquiryType_Changed" runat="server" ID="dropEnquiryType" CssClass="dropdownRequestList">
<asp:ListItem Value="Customer Services" Text="Customer Services"></asp:ListItem>
<asp:ListItem Value="Website" Text="Website"></asp:ListItem>
<asp:ListItem Value="Contract" Text="Contract Hire"></asp:ListItem>
<asp:ListItem Value="Other" Text="Other"></asp:ListItem>
</asp:DropDownList>
codebehind:
protected void dropEnquiryType_Changed(Object sender, EventArgs e)
{
lblComments.Visible = dropEnquiryType.SelectedValue == "Other";
textComments.Visible = lblComments.Visible;
}
If you absolutely have to do this within C#, then a simple check in PreRender should be sufficient:
textComments.Visible = (dropEnquiryType.SelectedValue == "Other");
This will also require you to set AutoPostback on dropEnquiryType, though, which uses ... JavaScript!
I have an commandfield and few templatefields. The templatefields have validators attached to it and they show up proper messages when wrong data is selected. However when I click commandfield no error is shown and the event fires even though data is invalid. Morover, I have also checked Page.IsValid on server and all works out well even though data is in invalid state. This the markup:
<asp:TemplateField HeaderText="Exp. Date">
<ItemTemplate>
<asp:Label ID="lblExpiration" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Expiration")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:DropDownList ID="ddlMM" runat="server" ValidationGroup="vgExpDateGrid">
<asp:ListItem Value="-1">MM</asp:ListItem>
<asp:ListItem Value="1" >01</asp:ListItem>
<asp:ListItem Value="2">02</asp:ListItem>
<asp:ListItem Value="3">03</asp:ListItem>
<asp:ListItem Value="4">04</asp:ListItem>
<asp:ListItem Value="5">05</asp:ListItem>
<asp:ListItem Value="6">06</asp:ListItem>
<asp:ListItem Value="7">07</asp:ListItem>
<asp:ListItem Value="8">08</asp:ListItem>
<asp:ListItem Value="9">09</asp:ListItem>
<asp:ListItem Value="10">10</asp:ListItem>
<asp:ListItem Value="11">11</asp:ListItem>
<asp:ListItem Value="12">12</asp:ListItem>
</asp:DropDownList>
<span class="green"></span> /
<asp:DropDownList ID="ddlYY" runat="server" ValidationGroup="vgExpDateGrid">
</asp:DropDownList>
<span class="green"></span>
<asp:RequiredFieldValidator ID="rfvddlMM" ControlToValidate="ddlMM" Display="Dynamic" InitialValue="-1" runat="server" ValidationGroup="vgExpDateGrid">*</asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="rfvddlYY" ControlToValidate="ddlYY" Display="Dynamic" InitialValue="-1" runat="server" ValidationGroup="vgExpDateGrid">*</asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField
UpdateText="Update" CausesValidation="true"
HeaderText="Update" ShowEditButton="true"
EditText="Update <br/>Exp. Date" ButtonType="Link" />
Please do not pay attention to the weird control names and styles. Basically the template field has dropdownlists of year and month. Year's drop down list is populated in rowdatabound event. As you can see validators are attached still commandfield works normally. Can anybody tell me what can be the problem?
At first glance I would say you do not have ValidationGroup="vgExpDateGrid" on asp:CommandField. Change your commandfield to:
<asp:CommandField ValidationGroup="vgExpDateGrid"
UpdateText="Update" CausesValidation="true"
HeaderText="Update" ShowEditButton="true"
EditText="Update <br/>Exp. Date" ButtonType="Link" />
or alternatively remove ValidationGroup from asp:RequiredFieldValidator