I have model where exist code for init items for MultiSelectList.This MultiSelectList contain a lot of items and this items reading from external services or database this is doesn't matter. Lets imagine that this reading is slow in any case.
[Code]....
But In Controller when user made Post Back and I also reload this items because InvoiceViewModel not contain items in collection what bind to MultiSelectList he contain only selected items.I have idea save this list in global object.How and where I can store global object in MVC ?
Values in multiselect dropdown not getting selected when Select All option is selected for a SSRS dropdown. There are multiple dropdowns on the page. We have one dropdown whose output is being used to populate the second dropdown using a stored procedure. When we check the Select All checkbox on the dropdown then ideally upon page refresh all the values should get selected in the dropdown, but in this case the page refreshes back to the blank dropdown, forcing the user to select the values again. The next dropdown too does not get populated. This makes it impossible to run the report for all the cases by using Select All. We ran the report on differnet database environments. My current location is Mumbai,India, the report worked fine when we ran it on a Bangalore,india database. This issue occurs when we try running it on a Chicago database server. I am using SSRS 2005, SQL2005.
My problem is I need to set selected value of a drop down list to a value I retreive from a database. The example only has a know value.
Below is the HTML and Code. <asp:DropDownList id="ddlCatogory1st1" DataSourceID="srcCatogory1st1" DataTextField="CategoryName" DataValueField="CategoryID" AutoPostBack="true" Runat="server" /> <asp:sqldatasource id="srcCatogory1st1" ConnectionString="server=(local);database=db;Trusted_Connection=true" SelectCommand="SELECT CategoryID, CategoryName FROM Categories WHERE ParentCategoryID is null ORDER BY CategoryID" Runat="server" ></asp:sqldatasource> Sub Page_Load() DISPLAY_CATEGORY() End Sub Sub DISPLAY_CATEGORY() ddlCatogory1st1.DataBind() ddlCatogory1st1.Items.FindByValue("A").Selected = True End Sub
When I run this page I get
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 222: Line 223: Sub DISPLAY_CATEGORY() Line 224: ddlCatogory1st1.DataBind() Line 225: ddlCatogory1st1.Items.FindByValue("A10").Selected = True Line 226: End Sub
Even if I take out the databind I get the same error.
I've been all over the Internet looking for an acceptable solution to this issue, but didn't find one, so hopefully I'll have more luck here. I've got a Html.DropDownList control in my application that pulls in a set of values from the database. That works just fine. However, I want to set the selected value in code, which has never worked correctly. This is, in my opinion, one of the worst implementations of Html helpers in MVC. Here's the culprit:
[Code]....
OK, it takes in a list of statuses and gets the text/value options set without a problem, but doesn't ever render the selected value on the option with a value (ID) of "5". I've stepped through the code as it is assigning these values, and it does set the value of that option to select = true, but the rendered html doesn't reflect this. I recall something about this helper using the Model to set its selected value, but why will it not allow the value to be explicitly set? Even better, if for some reason explicitly setting this in code isn't going to work, why allow it as viable code, and just silently fail? I'm all for this coding by convention approach MVC has taken, but when the convention is explicitly overridden in code, the code should prevail, I would think.
A sorting requirement changed and the client wants to have the last edited record appear at the top of the listview. So after the save, the ListView is getting updated as I am using AJAX and not taking it out of edit mode. If the record the were editing was #3 in the list, it would move up to the first row now, but the ListView is still highlighting row 3.
I am capturing a GUID in just setting it to "display:none" on the tag. So I have a unique to work with if I need to. Is there a way to accomplish this in C# code-behind?
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 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 CheckboxList that seems to load and do everything right, except for when I do a postback, it will not have the Item.Selected property set. I have viewstate disabled for the entire page.
I load it like so(inside Page_Load on every load): foreach (DataRow service in d.Tables[0].Rows) { [code]...
and MyLabel never has any text added to it. I can verify with the debugger that it does reach the _Click's foreach loop, but no item is ever selected. What could be the cause of this?
I am not trying to achieve anythign fancy but just trying to set default selected value for one of the dropdown that I am using. for that I am doing Items>selected= true for whatever item I want selected when i load the page. In my case, it is a month dropdows and I am selecting date 14 as selected default value out of all 30 values but somehow, out of the blue .NEt decides to show me 29 instead of 14. I am not sure if there is some another setting that is overwritting this value.
I have a master page (Site.master) with a navigation menu linked to a datasource (Master.sitemap). I have a nested master page that has another navigation menu. For any item clicked in this nested navigation menu, I want a particular menu item in the Site.master navigation menu to be selected.
Here's my Site.master menu: [Code]....
In my Site.master.cs I have this: [Code]....
In the nested master page, Products.master I have this: [Code]....
In the Products.master.cs file I try to change the selected item. [Code]....
The master navigation and products navigation menus work just fine by themselves. But when I've tried to set the selected item of the master menu in the Page_Load above, I can't seem to access it. What I've found in trying to do this is the NavigationMenu seems to be uninitialized. The menu Items list is empty. What am I missing here? Why are there no menuItems in the Master.NavigationMenu control?
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 have a setup.aspx page where in i select the theme with buttons so if i click on a button the theme should reflect in all of my pages of project.so how can i write the code do i need to call it in each page.how can i set the initial page to do so.
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'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?
public DateTime fromdate { get; set; } public DateTime toDate { get; set; }
I am setting this values in my code behind. After setting the values i want to reload the usercontrol so that it fires a get method which will use these dates ...how will i reload the usercontrol
Not sure if this falls under security but I figured since its about logging in it might. Anyway. I would like to know if my approach is good. I have set up a login, the Login method is under the User Class which uses validation to my own database (not ASPNETDB). I would also like to set values to that user to use on each page such as a simple label on the home page that says "Hello [UserName]". Code is below, should I separate the User values into a different class? Also once i go to another page (called Home.aspx) I would like to set an ASP Panel to have the username in it. I created a new instance of the User class in Home.aspx but unsure what I would need to go to get this to work. Should I have some LoadUser method after a successful login?
i have a page where i have a search area for users and a blank table. When a user performs a searcg,im creating in the cs the rows for the table and adding in the cells textboxes with values from DB. The textboxes ID´s are also being retrieved from the DB. Then, the user can change values from the textboxes. I also have an asp button that´s supposed to save the changes BUT i cant manage to persist the ids and last values between postback. Ive tried something ClientScript.RegisterArrayDeclaration but the array comes up empty. Then i used a hiddenfield but does the same trick.
what am i doing wrong?I add the hiddenfield,i try to add all the controls ids to an array but seems impossible,and there is no way i am getting the last values in another array. Im loosing everything between postbacks, but if i manage to save these ids and values, ill re-make the table in a sec.
I have a form with a checkbox list, the values of which are value = "1" value = "2' ...etc (amount of boxes not fixed). These values correspond to an id field in a database and are stored when a new user is entered. When reloading this info I want to populate the checkboxes according to how the user originally checked them. What is the correct way to do this?
while (reader.Read()) ( i = Convert.ToInt16(reader["Id"]); CheckboxList1.Items.FindByValue[i].Selected = true; }
Property3 and Property4 anre both public properties of the page I am on and the user control
Currently the code complaing about Property3 saying it cannot create an object of Int32 from '<%=Property3%>' and Property4 always gets set to 0 (the default)
I do not wish to use the c# code to set these values as this Plugin will be deployed with a CMS which I have no control over