I am trying to populate the DropDownList from the codebehind. If this was not contained in a FormView, I would normally just do it in the Page_Load event. However, that does not work within a FormView, as as soon as I try to do it, accessing the dropdownlist in code, ie: theListcontrol = CType(formView.FindControl(listControlName), System.Web.UI.WebControls.ListControl)
the data binding mechansim of the FormView is invoked, which, of course, tries to bind the DropDownList to the underlying datasource, causing a *'ParentMetricCode' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value * error, since the DropDownList has not yet been populated. I tried performing the load in the DataBinding() event of the FormView, but then:
theListcontrol = CType(formView.FindControl(listControlName), System.Web.UI.WebControls.ListControl) fails, as the FormView.Controls.Count = 0 at that point. Is this impossible? (I do not want to have to use a secondary ObjectDataSource to bind the dropdownlist to)
Assuming i have two dropdownlists namely: dropdownlistA and dropdownlistB. at page load, i bind values to dropdownlistA. however, depending on the value selected or displayed in dropdownlistA, i want to bind data to dropdownlistB.
Currently, i can bind data to dropdownlistA alright and i already have the required dataset and datatable bind data to dropdownlist. However, dropdownlistB does not bind at page load since the criteria for filling the dataset to bind dropdownlistB (which is the value of dropdownlistA) is not selected. how can i make this wwork.
I am currently considered if this might work. If i were to call the databind for dropdownlistA in a different declared method besides its binding in page load, and select the value from bind in the declared method, would any value be selected?
For example:
In during page load, i call the a method that returns dataset values which i bind to dropdownlistA(caseIDDropDownList). then i call another method (CreateexhibitDataSet()) which contains the dataset values for binding dropdownlistB(exhibitDropDownList). however, i need to define a criteria in the CreateExhibitDataset() method which i will use to generate the dataset values to bind dropdownlistB. if i were to call for the data bind of dropdownlistA(caseIDDropdownList) again in the CreateExhibitDataset() method and pick the value in the dropdown list, would i get any values?
How can i work around this to bind both dropdownlists on page load?
I know this sounds like a dumb requirement but the company I work for needs to be able to load a rather large list of employees. I am using a listview to select the FK_ID of the employee and then display their name. Once the user clicks edit, I then allow them to select the list by using a Button and load the user control of the massive dropdownlist. The problem is that it lags the program really bad. I will show code soon. Is there an easier way to achieve a fast loading page with large volume controls?
I am storing html of error pages of my site in sql table, i want to display them in a window, on the admin side, but not able to load the saved html in iframe, i am using asp.net mvc2.
its needed to save the pages, and display later to admin.
Does anyone know how to load the HTML element of https in asp.net?say.. you have the following url: https://somesite.com/secure/site.aspx. How do I programatically load the html content of the this url?
I posted a similar question previously, but none of the answers worked and I've been scouring all over the web trying to find a solution. My situation, I have a Edit Window webform with a dropdownlist (Note: to avoid confusion, I'm using Telerik extensions only to decorate the webform):
And in the code behind, I'm setting the datasource for the dropdownlist and using a function to query the DB for the name of the value I want to set as the selected value when the page loads initially: Partial Class EditFormVB Inherits System.Web.UI.Page
Public Shared category_Name As String = "" Dim ddlDataSource As New SqlDataSource Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init DetailsView1.DefaultMode = DetailsViewMode.Edit End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.Page.Title = "Editing record" ''Setup DropDownList SqlDataSource ddlDataSource.ID = "ReqCategoryData" Page.Controls.Add(ddlDataSource) ddlDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("TTPRODReportsQuery").ConnectionString ddlDataSource.SelectCommand = "SELECT TS_NAME AS ReqCategory FROM dbo.TS_SELECTIONS WHERE (TS_FLDID = 5299 AND TS_STATUS = 0) ORDER BY TS_NAME" Dim args As New DataSourceSelectArguments ddlDataSource.Select(args) ''Set max length of Title field to 70 characters Dim dvrTest As DetailsViewRowCollection = DetailsView1.Rows Dim TitleTB As TextBox = dvrTest.Item(0).Cells(1).Controls(0) TitleTB.Attributes.Add("onkeydown", "isMaxLen(this)") TitleTB.Attributes.Add("maxlength", "70") Dim myDDL As DropDownList = DetailsView1.FindControl("reqCategoryDropDown") ''Perform dropdown list population operations If Page.IsPostBack = False Then Dim ticket_ID As String = getDataKey(DetailsView1) ''Fetch Category ID Dim sqlText As String = "SELECT TS_REQCATEGORY FROM USR_ITFAC WHERE (TS_ID = " + ticket_ID + ") " Dim reqDataReader As SqlDataReader = GetDataReader(sqlText) reqDataReader.Read() Dim category_ID As String = reqDataReader(0) ''Fetch Category name using the categoryID and set as selected value in dropdown list sqlText = "SELECT TS_NAME FROM TS_SELECTIONS WHERE (TS_ID = " + category_ID + ") " reqDataReader = GetDataReader(sqlText) reqDataReader.Read() category_Name = reqDataReader(0) myDDL.DataBind() myDDL.Selectedvalue = category_Name //<--this value gets set only when debugging, End If End Sub Private Function GetDataReader(ByVal sqlText As String) As SqlDataReader Dim dr As SqlDataReader Dim sqlConn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("TTPRODReportsQuery").ConnectionString) sqlConn.Open() Dim sqlCmd As SqlCommand = New SqlCommand(sqlText, sqlConn) dr = sqlCmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection) Return dr End Function End Class
The dropdownlist does get populated appropriately, however when I attempt to set the value, it doesn't reflect when the page loads; the dropdownlist just gets populated and no value is set to selected in the markup, so the first value is shown by default. The odd thing is that when I'm debugging, the value appears to get set when I step through the function, it's as if the selectedvalue is getting reset as soon as the function exits and proceeds to load the page.
SOLUTION: Had to add a separate function that is called onLoad from the DropDownList after the after Page_Load is done executing. Still unresolved is why the the DropDownList rebinds after the Page_Load.
IN HTML: <asp:DropDownList DataSourceID="ReqCategoryData" DataTextField="ReqCategory" DataValueField="ReqCategory" ID="reqCategoryDropDown" runat="server" AutoPostBack="true" OnLoad="DDL_DataBound"> IN CODE-BEHIND Public Shared category_Name As String = "" Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.Page.Title = "Editing record" ''Setup DropDownList SqlDataSource ddlDataSource.ID = "ReqCategoryData" Page.Controls.Add(ddlDataSource) ddlDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("TTPRODReportsQuery").ConnectionString ddlDataSource.SelectCommand = "SELECT TS_NAME AS ReqCategory FROM dbo.TS_SELECTIONS WHERE (TS_FLDID = 5299 AND TS_STATUS = 0) ORDER BY TS_NAME" Dim args As New DataSourceSelectArguments ddlDataSource.Select(args) ''Set max length of Title field to 70 characters Dim dvrTest As DetailsViewRowCollection = DetailsView1.Rows Dim TitleTB As TextBox = dvrTest.Item(0).Cells(1).Controls(0) TitleTB.Attributes.Add("onkeydown", "isMaxLen(this)") TitleTB.Attributes.Add("maxlength", "70") Dim myDDL As DropDownList = DetailsView1.FindControl("reqCategoryDropDown") ''Perform dropdown list population operations If Page.IsPostBack = False Then Dim ticket_ID As String = getDataKey(DetailsView1) ''Fetch Category ID Dim sqlText As String = "SELECT TS_REQCATEGORY FROM USR_ITFAC WHERE (TS_ID = " + ticket_ID + ") " Dim reqDataReader As SqlDataReader = GetDataReader(sqlText) reqDataReader.Read() Dim category_ID As String = reqDataReader(0) ''Fetch Category name using the categoryID and set as selected value in dropdown list sqlText = "SELECT TS_NAME FROM TS_SELECTIONS WHERE (TS_ID = " + category_ID + ") " reqDataReader = GetDataReader(sqlText) reqDataReader.Read() category_Name = reqDataReader(0) myDDL.DataBind() End If End Sub Protected Sub DDL_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) If Page.IsPostBack = False Then Dim myDDL As DropDownList = DetailsView1.FindControl("reqCategoryDropDown") myDDL.Items.FindByValue(category_Name).Selected = True End If End Sub
I have payment form with a clients dropdownlist that is populated from a database on form load with:
value field = clientIdtext field = nameId <asp:DropDownList ID="selClients" runat="server"> </asp:DropDownList>
When user makes a payment, it's necessary to chose a client from selClients, and so i get the clientsId value and build my insert SQL query.
Until here, no problems.
The problem with my UI has started since i had a lot of clients been registered: My dropdownlist became huge and it's taking too much time to load it's contents on page load. Also the dropdownlist area is taking a large area from page screen.
So i tryied a solution with jquery autocomplete plug in. I put a textbox with autocomplete for client name and another hiddenfield to receive the clientId when user select a item.
That solves both problems:
No more large amout of data loaded on page loadThe dropdownlist doesn't take a large area from page screen But it gave me another problem!
With a textbox, there is a possibility for wrong input client name. So if i don't have a valid clientId in hiddenfield, it will generate a database INSERT exception because it doesn't respect the client table constraint:
payment table REFERS client table
I'm trying to find kind of dropdownlist where the user can type text with autocomplete. Like this, the user will be able to select only data within the possibilities of the dropdownlist and i always will have a valid clientId.
what i am trying to achieve is that. when any of the links is clicked. the <a href> tags are replaced by <span> tags. Is this possible? i tried playing aroung with HtmlGenericControl class but i could not solve it.
I want to load part of a html-file (content.htm) in my project into an iframe in my main page (main.aspx).
Also, I want that content to take on the css, javascripts and filepath of the main page.Is this even possible?
It seems iframe is almost a separate browser, and no settings from the main page will affect it. CSS does not work, nor does the filepaths since the content.html is located in a subfolder.
I have a drop down box , it has value that is retrieve from datasqlsource, however i want to get the count value on page load but it seem that it did not count
'Dim adapter As New SqlDataAdapter 'Dim ds As New DataSet 'Dim connectionString = ConfigurationManager.ConnectionStrings("myProject").ConnectionString 'Dim myConn As New SqlConnection(connectionString)
We are facing many challenges in using HTML dropdownlist in MVC web role. We want to get the value of the item selected by user from dropdown and based on that we want to populatee value of another text box. However whenever we tray to do so we always getthe value null b'coz ViewData returns null. In case any one has tried this kind of scenario, then plesae share your complete code - HTML declaration as well as the corresponding Action Result?
I have a partial class extending my Entity Model. I'd like to write a method that returns a collection of types from my entity framework model. For example, I'd like to get all the states to populate a drop down list. So I've written a method called getallstates(), similar to the example below:
[Code]....
I tried returning a list of Objects, and a list of states to my calling method to be used to bind to a drop down list. However I get an error that:
Server Error in Application. Unable to cast object of type 'System.Data.Objects.ObjectQuery to type 'System.Collections.Generic.List`1[System.Object]'.