C# - AJAX CascadingDropdown - Setting The Selected Index
May 5, 2010
I have a CascadingDropDown on an ASP.NET page. Now, the prompt text is "Select State". (list of states). However, on a different version of this page (ie querystring), i might want to set the selected index to "California" for example. How can i do this? The web service used by the ajax control (ie GetStates) gets invoked at the same time the jquery document.ready function is triggered (ie asynchronously).
So when i try and set the selected index in jquery, the items are not yet bound. Is there a way to attach a handler to the ajax dropdown so that i can set the selected index once the webservice call has completed, and the items are bound?
I have looked high and low and have not found what I need or found something that could work but it was old and did not work. I have a datalist (in an update panel) that contains 2 dropdownlist (Categories and Sub Categories) being populated by CascadingDropDown. What I want to do is set the selected index of the First one to the value I get from the Database after populating it in the web service. Then based on that I would like to adjust the 2nd dropdown for the new selected index. Here is the ui code
[Code]....
I saw a post about CascadingDropDownProperties using Atlas but I cannot seem to find anything about the AtlasControlKit anymore (is it part of AjaxControlKit?)
I'm using a CascadingDropDown in my page and I need to do the following things :
- Getting the list of elements in the dropdown
- Setting a specific value to the dropdown if it exists in the list
I am a total noob in webservices and javascript so I would like to do this in the codebehind but when I try to get the items of my dropdown, the only one returned is the one that is selected on the client side.
Is there a way to get the full list from the codebehind?
I have a problem in setting the selected index /value in a drop down list. The list is bound by a Linq query and I want to add an item at the top of the list and set it as the selected item.
THis is the code i am using
ListItem li = new ListItem("Select", "", true); list.DataSource = (from ap in edc.Approvers where ! ap.approverEmail.Equals("") orderby ap.approverEmail select new {ap.approverEmail}).Distinct(); list.DataTextField = "approverEmail"; list.DataValueField = "approverEmail"; list.DataBind(); list.Items.Add(li); list.Items.FindByText("Select").Selected = true;
The listItem li is the item i want to be first in the list and also selected. Adding this before the databind just loses the item.
I have a datalist that holds imagebuttons which all link to images stored in a database. When I click on any of the image buttons the datalist enlarges the chosen picture and manages to dothis as the datalist is binded by the uniqueID of the image in the database. So, when I am looking at the enlarged picture, it would be nice to be able to click 'Next' & 'Prev' link buttons to move onto the next or previous picture without having to return to the datalist in between looking at a different photo.
I have managed to set up methods for clicking on 'next' and 'prev' linkbuttons that will successfully browse back and forth between photos in the datalist but the selected index always starts at 0, i.e the first photo in the datalist. So if I'm viewing the 5th image in the list and press 'next', the first image in the list shows up. I thought just by clicking on an image button would automatically set the selected index but obviously this is not the case. I have read various threads and tutorials on the net and a lot of them point to dlIcons.SelectedIndex = e.Item.ItemIndex; I have tried to put this in the itemDataBound method for my datalist but it changes nothing. And if i try to put that line of code in other messages in the class i get error messages (I'm using Visual Web Developer C#).
its part of a final year project due in 3 weeks and by now I should be writing the report! The code I'm using is pretty huge and spread out between classes but I will include what I think might help illustrate how it all works:
<asp:DataList ID="dlIcons" runat="server" DataKeyField="AttachmentID" OnItemDataBound="dlIcons_ItemDataBound" ItemStyle-BorderWidth="1px" RepeatColumns="5" RepeatDirection="Horizontal" CssClass="Icons" OnSelectedIndexChanged="dlIcons_SelectedIndexChanged"> <AlternatingItemStyle CssClass="AlternatingRowStyle" /> <ItemStyle CssClass="RowStyle" BorderWidth="1px" /> <HeaderStyle CssClass="HeadeBrStyle" /> <FooterStyle CssClass="FooterStyle" /> <SelectedItemStyle CssClass="SelectedRowStyle" /> <ItemTemplate> <asp:Label ID="lblFilename" runat="server" Font-Size="Small" Text='<%# Eval("Filename") %>' ></asp:Label> <br /> <asp:LinkButton runat="server" id="btnDelete" CommandArgument="<%# Bind('AttachmentID') %>" CommandName="DELETE" Text="Delete" OnClick="btnDelete_Click" Font-Size="small" CssClass="btnDelete" /> <br /> <asp:ImageButton runat="server" ID="imgBtnFileType" width="120" Height="120" ImageAlign="right" ImageUrl='<%#"http://localhost:49279/PDFViewer/GetAttachment.ashx?AttachmentID=" + Eval("AttachmentId") %>' OnClick="imgBtnFileType_Click" BorderWidth="1PX" CssClass="imgBtnFileType" CommandName="VIEW" CommandArgument="<%# Bind('AttachmentID') %>"/> <br /><br /> </ItemTemplate> </asp:DataList> The CS file: protected void dlIcons_ItemDataBound(object sender, DataListItemEventArgs e) { if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) { DataRowView drv = e.Item.DataItem as DataRowView; dlIcons.SelectedIndex = e.Item.ItemIndex; int attachmentID = (int)drv["AttachmentID"]; string fileType = (string)drv["Type"]; ImageButton imgBtnFileType = e.Item.FindControl("imgBtnFileType") as ImageButton; string fileName = (string)drv["FileName"]; Label lblFilename = e.Item.FindControl("lblFilename") as Label; lblFilename.Text = fileName.Length > 12 ? fileName.Substring(0, 10) + ".." : fileName; } } The next and prev link buttons onclick leads to these two methods: public int nextPic() { dlIcons.Items.Equals(dlIcons.SelectedIndex++); int nextAttach = (int)dlIcons.SelectedValue; return nextAttach; } public int prevPic() { dlIcons.Items.Equals(dlIcons.SelectedIndex--); int prevAttach = (int)dlIcons.SelectedValue; return prevAttach; }
these were void methods but i've been stuck on this for hours and have resorted to fiddling with just about everything.
I am using the AJAX Contol Toolkit and 4 CascadingDropDown extenders with an ODBC connection in a Web Service. The original load of values in each level works great. I then use these values to set the create the SQL for the SelectCommand for a Gridview.
The problem I am having is that when I submit the page to perform the search, the first 2 dropdowns repopulate and set the selected index accordingly, but the 3rd dropdown does not retain its selected value. It does populate with the values, but the selected value does not get set.
The correct values are available for the SelectCommand which returns the correct values.
In normal case both header texts (More search options and less search options) are visible.I want only one header text is visible at a time.ie;either more search options or less search options.
can we write code in accordian selected index changed?
I have a modalpopup control which has a gridview and search criteria. User selects a records and clicks modalpopup ok button ( which is set as modalpopup's okbutton). I have attached an event to okbutton click event. and inside this event, I am setting a label control which in on main page which called this modalpopup. I debugged code, it comes inside that event but doesnt set value. below is my event code.
I have a radio buttonlist in my webpage with 2 list items, when I click the 2nd list item I want to change the visibility of a text box so it wore the code
I am trying to give animation effect to a label , when user select option from radio buttonlist for selectedindexchange event , but i cannot get animationextender for this event.because <onLoad> <onClick> ..... list does not have <onSelectedindexchanged> option. how to do this I saw a code which adding animation effect from server side, though i have problem of excute on radiobutonlist index change event.
How to get the selected item from the listbox in the selected index changed event. I tried: Label1.Text = ListBox1.SelectedItem.Text; It is giving me object set to null reference.
foreach (ListItem item in ListBox1.Items) { if (item.Selected) { //lblResults.Text += item.Text + " "; Label1.Text = item.Text; } }
I have two control page in my aspx page. first one left side "tree view",second one right side " form design".Form design will change based on tree view selected index changed.i have 4 level child node(site, master , slave, space). I have seperate forms to each level of node.
cannot update tree node when update the forms. so i reload tree view.
now i need how to auto selected index change to tree node.
ex.
1 parent node
1.1 child node
1.2 child node
i have update "1.2 child node" rename to "1.3 child node"
and reload treeview so it will chage...
how set tree node.selected index = 1.3 child node....
I gave tab index value for TextBox as 1 and CheckBox as 2 by setting TextBox to default focus. The Problem is after the page is loaded when I press tab, insted of moving focus to checkbox, URL bar of the browser is getting focused.
I am binding months to a list 0-13 items default selection is 0 months duration, and years 0-8 items and 0 years is the default selection.As I know there are always going to be 12 months in a year, I could use selectedvalue or selectedindex without any perceived problem. Is there a reason why I should not use either/or of the two properties to select a list item?
I have a request:((( Now I can use the TextBox auto-complete but my problem that i use (Key/Value) mean that I should display for example the country name and use the country iso code in the code behind.... so how can I do that by using ajax (TextBox or DropDownList)
Is it possible to add a new item to cascadingdropdown? I tried ddl_master.Items.Insert(0, "3"), but it doesn't show up. When I view the source in the browser it's there.
I use the CascadingDropDown to fill several DropDownList in my web to manage different application access rights
I use the Ajax CascadingDropDown component for that.
My problem is that, depending on the application, the selections criterias of the values in my database will be different.
I would like to know if there is a way to get or to identify the name or the ID of the dropdownlist which execute the CascadingDropdown class in the .asmx part (in the "public CascadingDropDownNameValue[] GetApplication1(...)" class ) ??
The name of the DropDownList give me the code of the application manage use to select my data in my SQL query
I don't want to write several query for each dropdownlist like :
public CascadingDropDownNameValue[] GetApplication1(...), public CascadingDropDownNameValue[] GetApplication2(...) etc ...
as they will be create automatically at the loading of the page.
i am using ajax cascading ddl for binding customer, package, device and leadcount.. i need to bind the package by customer, device by customer & package, leadcount by customer & package & device. but we can pass only one value to the webservice method when binding.. but i need to pass 2 or 3 values to the webmethod. how can we do this. also when i select the customer i need to bind all the 3 controls. but in ajax cascadeing ddl we can give 1 parent control id only. i need the solution for this also...
I've implemented a cascadingdropdown solution using the demo video here on ASP.NET.
Below is my code for one of my sub-categories. I want to have my sub category controls hidden and only show them if there are sub-categories (not all categories have sub-categories)
So, my question is how to get the count of the subcategories returned by method below and turn on the visibility of the dropdown control from the web method?
I have two sets of cascading drop down lists they are contained in a detailsview <edititemtemplate>. The problem is that when the user clicks update; the original data is wiped out and the user has to redo the selection of all items contained in a cascading dropdown even if the user didn't want to change that particular aspect of a record. If the user doesn't select everything an error is thrown by the stored procedure in regrds to null values not being valid.
Is there a way i can use cascadingdropdown so that the current values are visible when the user clicks update; meaning that they don't have to redo selections for all items involving drop down lists. The current selections would be default values.