.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

unable to get dynamic generated dropdownlist item

Posted By:      Posted Date: September 22, 2010    Points: 0   Category :ASP.Net

hi sir,

i'm using asp.net 3.5 and what im trying to do is create the dropdownlist item dynamically base on value in each datarow, then user select from dropdownlist and click button to postback, when postback system should be able to know what value has been selected by user. the problem with following code is during postback, event of "OnItem_Created" get fired and e.Item.DataItem return null, therefore the dropdownlist will not get populated with the items and that caused the dropdownlist unable to return value selected by user. am i missing anything? is "OnItemCreated" the best place to dynamic create the dropdownlist item? any help will be appreciate. thanks!!

    <form id="form1" runat="server">
      <asp:Button runat="server" ID="btn" Text ="go" />
      <asp:DataGrid runat="server" ID="grd"  OnItemCreated="OnItem_Created">
              <asp:DropDownList runat="server" ID="ddl">

View Complete Post

More Related Resource Links

DropDownList problems : The ViewData item that has the key 'userTYPE_id_user_type' is of type 'Sy

Hello,I've been searching for that problem for hours...I have two table :          -user          -userTypeI'm trying to create a user, wich as a column id_userType, so I'm trying to do a dropdownlist with the userType List I've that error code : The ViewData item that has the key 'userTYPE_id_user_type' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'. // // GET: /User/Create public ActionResult Create() { //Send to the view, the userTypeList IEnumerable<SelectListItem> userTypeList = new SelectList(_userRepository.FindAllUserType().Distinct().ToList(), "id_user_type", "Description"); ViewData["userType_id_user_type"] = userTypeList; return View(); } here the post controller // // POST: /User/Create [HttpPost] public ActionResult Create(users user) { if (ModelState.IsValid) { try { _userRepository.addUser(user); _userRepository.save(); return RedirectToAction("Index"); } catch { return Vie

ListItem Dynamic DropDownList based on custom list entries.

I utilized the following solution to get the drop down list on the page and populate it dynamically, but it doesn't save the selected value back to the SPListItem object. Does anyone have a better solution possibly for this? http://geekswithblogs.net/SoYouKnow/archive/2010/01/21/sharepoint-populating-drop-down-list-field-with-data-from-different.aspx

Unable to Show Edit item Links in Data Form Web Part

I have a DFWP connected to custom list and the boxes to Show Edit Item Links, Show Delete item links and Show Insert Item links are grayed out so that they can not be checked. This works fine when I use a DFWP connected to a standard list (i.e., Contacts). Is there something special that needs to be done to activate this functionality?ThanksDean

Dynamic list item title based on date created & regional settings?

I have a list of things that doesn't *need* a title.  However, because sharepoint uses Title for links, RSS etc  I tried generating a title in an event handler.   This would work great if I wasn't basing it on a date field: public override void ItemAdding(SPItemEventProperties properties) { DateTime dt = Convert.ToDateTime(properties.AfterProperties["TestDate"]); properties.AfterProperties["Title"] = dt.ToShortDateString(); base.ItemAdding(properties); } In testing, this sets the title to "8/9/2010" when I selected 8/10/2010 in the date picker.  I figure this is because of the regional settings of my test user.  I can probably correct the title value for 'test user' but that won't fix 'test user in mongolia' who would still see two different values. So What I would like is to have the Title always display the value MyDate in the uesr's locale.  So the field needs to be dynamic not only at edit/update time, but at display time. Does anybody know if this can be accomplished, and more specifically how?

Dynamically add item to DropDownList??

I have an Edit page in my application that contains a DropDownList. This DDL is bound to an EntityDataSource that only shows the active "ProjectManagers". In the case where the user is editing a record that is assigned to an "inactive" ProjectManger, an "ArgumentOutOfRange" Exception is (rightfully) thrown by the DDL (because that Item wan't bound to the list, since it only binds "Active" ProjectManagers). So, I need to add this item to the DropDownList dynamically or at least add an "Inactive" item and then "select" that item in the code behind. (Although, adding an "Inactive" item would force the user to actually change the ProjectManager and that wouldn't be a good idea.) I have tried handling the OnDataBinding method with the following code:   protected void PreventErrorOnBinding(object sender, EventArgs e)    {        DropDownList theDropDownList = (DropDownList)sender;        theDropDownList.DataBinding -= new EventHandler(PreventErrorOnbinding);        theDropDownList.AppendDataBoundItems = true;        ListItem li = new ListItem(""<<Inactive>>", "0");     

Unable to access VM network drive in SQL during backup generated by stored procedure

I get the following error in a log file created in the osql command: Msg 3201, Level 16, State 1, Server KAC2KGS2, Procedure usp_Kaman_Full_SqlDB_Backup, Line 150Cannot open backup device 'x:\Servername_master_sqlbu_200703101930.bkf'.Device error or device off-line. See the SQL Server error log for moredetails.Msg 3013, Level 16, State 1, Server KAC2KGS2, Procedure usp_Kaman_Full_SqlDB_Backup, Line 150BACKUP DATABASE is terminating abnormally. The device is established in a CMD file right before the osql command is started that starts my stored procedure.  The CMD in this file is: for /f "tokens=15 delims=." %%i in ('ipconfig^|find "IP Address"^|find "192.168"') do set SUBNET=%%i :loopif exist x:\ net use x: /delnet use x: \\192.168.%SUBNET%.1\backup if not ERRORLEVEL 1 ( goto continue) else ( echo FAILED TO CONNECT TO BACKUP SERVER >> "%SystemDrive%\LogFiles\%Computername%.log" sleep 60 goto loop) :continue echo IP ADDRESS OBTAINED Echo delete old log file if it exists if exist %3\%computername%_kaman_full_sqldb_backup_old.log del /Q %3\%computername%_kaman_full_sqldb_backup_old.log Echo Rename log file to old.log rename %3\%computername%_kaman_full_sqldb_backup.log %computername%_kaman_full_sqldb_backup_old.log echo backup SQL Databases on server will start now osql -E -n -d %1 -i %2\kaman_full_sqldb_backup.sql -h-1 -o %3\%Co

How to get item selected in dropdownlist

I'm searching and trying now for the last couple of hours, so I thought the community might help.I'm filtering the rows in a gridview using a ddlDate. Now, I want to request this selected item.But: When I load the page without clicking in the DropDownList, the ddlDate.SelectedValue is empty, and the ddlDate.SelectedItem.Text.ToString() gives a NullReferenceException.Is there any way to fix this without using a listbox?

Databound DropDownList Item Value Property Localization

I am using a databound DropDownList in which the item's Text field is set to a text representation of an identifier value of type int.  I am filling the Value field of the ListItem with the int value.  All of this is being done through the setup of the DataTextField and DataValueField settings of the DropDownList control. However, since both the item Value and Text fields are strings, obviously a conversion must be performed at the time of binding to convert the non-string value to a string value.  I am making the assumption that the ToString() method for the value is invoked in order to convert the int value into a string so that it can be stored in the Value property of the ListItem. Once selections are made, I read the Value property of the SelectedItem to perform an action.  It occurred to me that converting back to the original data type might present a problem if the wrong culture information is used to perform the conversion. My question is, in the case of non-string values being automatically converted for a databound DropDownList, what culture is used to perform that conversion?  My initial guess would be the CurrentCulture, simply because no object is required to supply a ToString() overload which allows the specification of an IFormatProvider object.  However, if the System.Convert object is used to perform the conversion

ASP.Net Dynamic Data - DropDownList Field Template with AJAX Cascading DropDown Extension

Hi all,   Have spent hours trying to create a Dynamic Data Field Template holding a DropDownList which is extended by the AJAX Cascading DropDown extension. Final form holds multiple cascading dropdown boxes. User selects Country (Land) then Postcodes, Counties (Provincie) are populated. Once postcode is selected then towns (Plaats) are populated.  The problem I am now facing is that the viewstate for the dropdown lists is not being saved/restored after an insert action or custom validation error. So basically the dropdown lists are being reset to their default values. Some code (if missing parts, just ask and I will post them) - Don't mind the code structures etc... needs some refactoring :) Attribute I created:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Data { [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] sealed public class CascadingDropDownParametersAttribute : Attribute { //public string TargetControlID; // The ID of the DropDownList to populate. public string Category; // The name of the category this DropDownList represents. public string PromptText; // Optional text to display before the user has selected a value from the DropDownList. public string

JQuery with dynamic ASP.NET controls (DropDownList)

I am mixing JQuery with ASP.NET webforms.  Adding dynamic controls and accessing the selected values with JQuery works differently under different circumstances and I am trying to establish the difference. Why does Senario 1 work in debug mode but not without breakpoints?  What does databinding to a GridView do that adding DropDownList controls to a asp:panel does not? Is there some sort of DOM registration going on in DataBind? All senarios use the same JQuery: var ddlCollection = $("select[name$='ddlDynamicDropDown']") Senario 1: Breakpoints on each line (Success) Add DropDownList controls to a asp:panel dynamically in the PageLoad method (Does the page lifecycle matter? OnLoad method instead?). Run the code Select values and click on a button firing a JavaScript function (Break in Debug) Break in JavaScript file Access the dropdowns and their selected values successfully Senario 2:  Run the Senario 1 code without breakpoints (Fails to locate the ddlCollection) Senario 3: Use a GridView (Success) Add values to populate the DropDownList controls to a Generic List. Bind the values to a GridView control containing the DropDownList controls Run the code Select values and click on a button firing a JavaScript function Use JQuery to Access the dropdowns and their selected values successfully.  

dropdownlist selected item problum

In gridview we have edit button whenever user click edit button i want to show particular data of dropdownlist as a selected data that is selected by user as a selected text of dropdownlistis there any solution ???

Dropdownlist not firing SelectedIndexChanged on first item with autopostback true

Hi: Has anyone ever found a work around for the well documented and well known bug, the dropdownlist bug? Specifically where the SelectedIndexChange event does not fire on the first listitem, althought both autopostback and enableviewstate are true? In other words, if the first three items in the dropdownlist are red, blue, green, if you select green, the SelectedIndexChanged will fire, but if you then select red, the first item in the ddl, the event will not fire. All listitems will fire the SelectedIndexChanged event, except for the very first listitem. The HACK has always been to include a dummy item as the first list time like"Select a Color" to get around the first item bug. I have got a situation where I cannot use that hack. Ideas?  TIA, Bill  

Dynamic DropDownList ListItemCollection - Event Handler

Hi and thanks in advance. Description: I am building drop downs dynamically then adding them to a panel, when postback occurs it does not hit my event handler. However I CAN get the event handler to be hit if I remove(comment out) the properties DataTextField and DataValueField while I am rebuilding the dropdownlist within OnInit on eachpostback. However when the dropdownlist is in this condition the sender to the eventhandler does not have it's properties like SelectedValue[Index] set. Step 1: Build and load a drop down. The following is the event handler for selectedindexchanged on the lists.  The drop down list is bound to a ListItemCollection that represent a few fields from a datatable. This dropdown is loaded into a panel and the panel in turn is loaded into a div. All of this functions as intended.protected void AnswerDDL_SelectedIndexChanged(object sender,EventArgs e) { int _nextQuestionID; DropDownList _ddlSender = new DropDownList(); _ddlSender = (DropDownList)sender; _nextQuestionID = Convert.ToInt32(_ddlSender.SelectedValue); DropDownList _newAnswerDDL = new DropDownList(); _newAnswerDDL = GetAnswerDropDown(_nextQuestionID); this.m_panel.Controls.Add(_ne

disable a single intem in dropdownlist or stop the ddl change event for a single item


hello guys,

I am trying something apart of my boundries, is there any way to disable a single intem in dropdownlist or stop the ddl change event for a single item.

any feadback would be appriciable.

Thanks and Regards

Inderjeet Singh Khalsa

Dynamic menu item in MenuItemTemplate (in SPGridView)




I am implementing a SPGridView in a webpart and would like to have dynamic row menus (with different menu items) based on some cell values. It seems that the answer is in the very-poorly documented property HiddenScript of a MenuItemTemplate object, which contains a custom javascript function which should return true if the menu item should be hidden, or false otherwise.


My question is - how do I pass arguments to this custom javascript function? This is how the sample code looks like:


SPMenuField colMenu = new SPMenuField();

colMenu.HeaderText = "Address";

colMenu.TextFields = "url";

colMenu.MenuTemplateId = "PresenterListMenu";

colMenu.NavigateUrlFields = "url";

colMenu.NavigateUrlFormat = "{0}";

Dynamically Generated Dynamic Menu Items Width Question


I have the following Menu:

<asp:Menu ID="MainMenu" runat="server" Orientation="Horizontal" 
	DynamicVerticalOffset="2" DynamicHorizontalOffset="2" 
	StaticEnableDefaultPopOutImage="false" DynamicEnableDefaultPopOutImage="false" >
        <StaticMenuItemStyle BackColor="#0099cc" ForeColor="#eeeeee" Font-Names="Arial" Font-Size="11" Height="18" HorizontalPadding="10" VerticalPadding="3"  />
	<StaticHoverStyle BackColor="#336699" ForeColor="#ffffff" Font-Names="Arial" Font-Size="11" />
	<DynamicMenuItemStyle BackColor="#0099cc" ForeColor="#eeeeee" Font-Names="Arial" Font-Size="10" Height="18" 
		HorizontalPadding="10" VerticalPadding="3" />
	<DynamicHoverStyle BackColor="#336699" ForeColor="#ffffff" Font-Names="Arial" Font-Size="10" />					
		<asp:MenuItemBinding DataMember="Item" TextField="Title" />
		<asp:MenuItemBinding DataMember="SubItem" TextField="Title" />						

Select Item from Dropdownlist


I have a dropdown list created via MVCContrib FluentHTML - how do I perform a postback when the user selects any item in the dropdownlist? 

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend