Forms Data Controls :: Databinding Dropdownlist Added To Form Via Placeholder?
Mar 31, 2011
I have a formview that has several dropdownlists in the EditItemTemplate. Some of the dropdownlists are added using placeholders. I can add and populate their listitems without any problem. But when I update the record, none of the controls can be found--even though when I look at the page source they are there. I first strated out using asp:ControlParameter in my sqldatasource updateparameters, but even referencing the control as myform$mycontrol did nothing. So then I moved to code behind on the sqldatasource.updating event (code is attached). The only controls I cannot seem to bind to the update are those added via the placeholder.
The item at the dim statement is not an item added using a placeholder and does not get a null reference exception (I used that to prove during debbugging that I wasn't losing my mind)--however, all the items being used to get the parameter values are getting null reference exceptions and are added via placeholders. Here is the code I'm using to set up the dropdownlists:
how to get the value of these controls so they can be used in my update?
I have a gridview in which I have two drop downs. One is populated with values that are static, so I have a regular sub that does that in the code behind. I tried to add code for databinding the other ddl to a datatable. I cannot get this to work. It just comes up empty. My asp code is fine, and the datatable definately has data in it - just nothing gets populated.
One other thing - the code for the static ddl has worked fine, but when I add this other block (either to the same sub as that, or dow the rowdatabound event) the static one doesn't work either.
I have many controls on my form, but in particular, I have 2 dropdownlists. 1 dropdown list has 2 values, and each value controls what the second dropdownlist displays. This is an edititemtemplate and both dropdowns have the selecteditem set via '<%# Bind("fieldname") #>' on page load.
THe problem is, if I change the value of the first dropdown, it errors out because the second dropdwon has a bound value that is no longer acceptable.
Can I cancel the bind of the second control, if the the first one is changed? I would like to cancel the bind, and update the values by using a different datasource depending on the value of the first dropdown or hardcode the new values.
If Dropdown1 has a value of "A" for example Dropdown 2 Shows Values "1", "2", "3"
If Dropdown 1 has a value of "B" , Dropdown2 Shows Values "4", "5", "6".
It binds fine initially, but if I change Dropdown1 from A to B, I want Dropdown2 to show the new values, maybe with a default of "Select an Item" and not error out b/c it's attempts to bind a value of 1, 2, or 3.
Bringing back to life an old post that I dont believe ever got solved: http://forums.asp.net/t/1562245.aspxThis may be an old thread .... but no answer was ever given ... and I too have a radio button list and DDL and am stuck in the EXACT same place. If I check one of the two data bound radio buttons, the DDL should repopulate with a different set of results. This works just fine EXCEPT .... the DDL cannot be databound. If I set SELECTEDVALUE of the control to a bind I get this error:Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.I have followed the advice on this page from various users, all to no avail....surely this can be done, and I assume quite simply. Anyone know the answer?
I'm dynamically adding a DropDownList to the GridView in edit mode and I have set the TextBox Visibility to False. In edit mode I can see the DropDownList and I'm able to select an Item from the DropDownList but not able to access the SelectedValue in RowUpdating Event. How to get the selectedvalue of this DropDownList?
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound If e.Row.RowType = DataControlRowType.DataRow And (e.Row.RowState And DataControlRowState.Edit) > 0 Then Dim ddl as DropDownList FillStateList(ddl) e.Row.Cells(4).Controls.Add(ddl)
ddl is the DropDownList that is added dynamically. And the default Textbox that is in the Edit mode is set to invisible. So there are actually two controls in the same cell in edit mode(TextBox is invisible).
I have a dropdown on page, a place holder and a save button on my form.Now, I am creating a textbox on selectedIndexChanged event of dropdown list and adding it to placeholder. And on button click I want to access the control, but on click event, I find the textbox as null. Here is my code
I am using list view to display the the data but i am getting an error like An item placeholder must be specified on ListView 'ListView1'. Specify an item placeholder by setting a control's ID property to "itemPlaceholder". The item placeholder control must also specify runat="server.Even i have specified the itemplaceholder id but no use still same error.
I'm creating an ASP.NET control dynamically based on a value selected in a dropdown; for instance the field can be a textbox or a checkbox (for now), and then it gets added to a placeholder control. However, I'm unsure how to retrieve the value - using the placeholder's FindControl method returns null although I'm specifying the ID when I create the control.
asp.net with vb. I thought this would be easy but have been reading for an hour and not found out how to simply repost a page where form data has been entered and return the page with some error messages about what was entered. I want to return the page with all input controls with the data just as the user entered them before submitting. the error messages are labels that were blank when the page is first loaded. preferably the page returns focused to the topmost error error message. if that can't be done I would populate some label at the top of the page with something to the effect that 'errors were found, scroll down to see the errors'
See what happens when you answer my questions! I come back! No good deed goes unpunished. I've built an Update form where my visitor can update data in dbase. I have a formview with several dropdown lists; none of which will update the table (all the textboxes, checkboxes and even Ajax enabled calendar work just fine). In the form below, visitor selects a CareerCluster from the ddl. Upon postback, the next ddl (pathwayListBox) populates with related data using the CareerCluster.selectedvalue in a query. At the same time, tsaOrgsDropDownList is also populated based upon the first ddl (CareerCluster).
When user selects from the tsaOrgsDropDownList the final ddl (tsaDropDownList) is populated. All this various selecting/populating works just fine on the form. The problem is: Nothing is updated to the table upon clicking the Update button. All other form fields do post as their supposed to except, I have other ddls on the page that are not related to the above series and they won't post either. My thought is that somehow, this is related to the postbacking going on. That posting back is overwriting the selectedValues with null or something.
<asp:FormView ID="courseUpdateFormView" runat="server" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" DataKeyNames="CTECourseID" DataSourceID="formviewSqlDataSource" Width="715px"> <FooterStyle BackColor="#C6C3C6" ForeColor="Black" /> <RowStyle BackColor="#DEDFDE" ForeColor="Black" /> <EditItemTemplate> <table align="center" width="700" border="1" cellpadding="10" cellspacing="2" bgcolor="White"> <%--A whole bunch of textboxes goes here--%> <tr> <td bgcolor="#dadada"> <strong>Number of HS Credits:</strong> <span>(Standards-based districts use the <em>Other</em> form field.)</span> </td> <td bgcolor="#FCCCCC"> <span><font color="red">Note: you must reselect HS Credits from the list or enter Other credits in the form field provided.</font></span><br /> <asp:DropDownList ID="numHSCreditsDropDownList" runat="server" TabIndex="3" ToolTip="Standards Based districts us the Other form field." ValidationGroup="HSCredits" AppendDataBoundItems="True" OnSelectedIndexChanged="numHSCreditsDropDownList_SelectedIndexChanged"> <asp:ListItem Selected="True" Value="0">--Choose One--</asp:ListItem> <asp:ListItem>0.5</asp:ListItem> <asp:ListItem>1.0</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td bgcolor="#dadada"> <strong>Career Cluster:</strong> </td> <td bgcolor="#FCCCCC"> <span><font color="red">Note: you must reselect Career Cluster from the list.</font></span><br /> <asp:DropDownList ID="careerCluster" runat="server" AutoPostBack="True" TabIndex="4"> <asp:ListItem Selected="True" Value="0">--Choose One--</asp:ListItem> <asp:ListItem Value="1">Agriculture, Food & Natural Resources</asp:ListItem> <asp:ListItem Value="2">Architecture & Construction</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td bgcolor="#dadada"> <strong>Pathways:</strong> <span>(Pathway as defined in the Cluster/Pathway model.)</span> </td> <td bgcolor="#FCCCCC"> <span><font color="red">Note: you must reselect Course Pathway from the list or enter Other Pathway in the form field provided.</font></span><br /> <asp:ListBox ID="pathwayListBox" runat="server" DataSourceID="CTECourses" DataTextField="ClusterPathway" DataValueField="ClusterPathway" SelectionMode="Multiple" Style="margin-left: 0px" TabIndex="5" Rows="3"> <asp:ListItem Selected="True" Value="0">--Choose One--</asp:ListItem> </asp:ListBox> <asp:SqlDataSource ID="CTECourses" runat="server" ConnectionString="<%$ ConnectionStrings:CareerTechEducationConnectionString %>" SelectCommand="SELECT [ClusterName], [ClusterPathwayID], [ClusterPathway], [ClusterCode] FROM [lkClustersPathways] WHERE ([ClusterCode] = @ClusterCode)"> <SelectParameters> <asp:ControlParameter ControlID="careerCluster" Name="ClusterCode" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> </td> </tr> <tr> <td align="center" bgcolor="#4A3C8C" colspan="2"> <asp:Label ID="occupationalStandardsLabel" runat="server" Font-Bold="True" ForeColor="White" Text="Occupational Standards"></asp:Label> </td> </tr> <tr> <td bgcolor="#dadada"> <strong>Source of Occupational Standards:</strong> </td> <td bgcolor="#FCCCCC"> <span><font color="red">Note: you must reselect Source of Occupational Standards from the list or enter Other Source of Occupational Standards in the form field provided.</font></span><br /> <asp:DropDownList ID="tsaOrgsDropDownList" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="TSAOrganization" DataValueField="TSAOrgID"> <asp:ListItem Selected="True">--Choose One--</asp:ListItem> </asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:CareerTechEducationConnectionString %>" SelectCommand="SELECT [TSAOrgID], [TSAOrganization] FROM [lkTSAOrgs] WHERE ([TSAClusterID] = @TSAClusterID)"> <SelectParameters> <asp:ControlParameter ControlID="careerCluster" Name="TSAClusterID" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> </td> </tr> <%--A whole bunch of textboxes, checkboxes and other stuff goes here--%> <tr> <td bgcolor="#dadada"> <strong>What is the Summative Assessment (Technical Skills Assessment) for this course:?</strong> </td> <td bgcolor="#FCCCCC"> <span><font color="red">Note: you must reselect Summative Assessment from the list or enter Other Summative Assessment in the form field provided.</font></span><br /> <asp:DropDownList ID="tsaDropDownList" runat="server" AutoPostBack="false" DataSourceID="TSAs" DataTextField="TSA" DataValueField="TSAID" Width="300"> </asp:DropDownList> <asp:SqlDataSource ID="TSAs" runat="server" ConnectionString="<%$ ConnectionStrings:CareerTechEducationConnectionString %>" SelectCommand="SELECT [TSAID], [TSA] FROM [lkTSAs] WHERE ([TSAOrgID] = @TSAOrgID)"> <SelectParameters> <asp:ControlParameter ControlID="tsaOrgsDropDownList" Name="TSAOrgID" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> </td> </tr> <%--A whole bunch of textboxes goes here--%> <tr> <td align="center" bgcolor="#dadada"> <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" /> <br /> <span><font color="maroon">* All fields except the Tech Prep Information are required.</font></span></div> </td> <td align="center" bgcolor="#dadada"> <asp:Button ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" /> </td> </tr> </tr> </table> </EditItemTemplate> </asp:FormView> <asp:SqlDataSource ID="formviewSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:CareerTechEducationConnectionString %>" SelectCommand="SELECT * FROM tblCTECourses WHERE (CTECourseID = @CTECourseID)" UpdateCommand="UPDATE tblCTECourses SET HSCredits = @HSCredits, CareerCluster = @CareerCluster, Pathways = @Pathways, TSAOrgs = @TSAOrgs, TSA = @TSA, LastUpdate = GETDATE() WHERE (CTECourseID = @CTECourseID)"> <SelectParameters> <asp:SessionParameter Name="CTECourseID" SessionField="CTECourseID" Type="Int32" /> </SelectParameters> <UpdateParameters> <asp:FormParameter FormField="numHSCreditsDropDownList" Name="HSCredits" Type="String" /> <asp:FormParameter FormField="HSCreditsOtherTextBox" Name="HSCreditsOther" Type="String" /> <asp:FormParameter FormField="careerCluster" Name="CareerCluster" Type="Int32" /> <asp:FormParameter FormField="pathwayListBox" Name="Pathways" Type="String" /> <asp:FormParameter FormField="tsaOrgsDropDownList" Name="TSAOrgs" Type="Int32" /> <asp:FormParameter FormField="tsaDropDownList" Name="TSA" Type="String" /> <asp:FormParameter FormField="TSAOtherTextBox" Name="TSAOther" Type="String" /> </UpdateParameters> </asp:SqlDataSource>
In the codebehind I've tried to set selectedvalue to session variable upon selected index changed like this:
Protected Sub numHSCreditsDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Session("HSCredit") = DirectCast(courseUpdateFormView.FindControl("numHSCreditsDropDownList"), DropDownList).SelectedValue End Sub
how to maintain state of placeholder. i have a placeholder in which i add many image controls dynamically but when my page get refresh all controls from placeholder gets removed from it. the enableViewstate of placeholder is set to true.
I'm new to asp.net. I have a page with formview to read, edit and insert data to sql server 2008. On the page there are textboxes, dropdownlists. The Dropdownlist1 is bound to a lookup table. I also have a pop-up page to add, delete and update data underlying table. The problem is after i insert a new record to the lookup table and close the pop-up page, rebind the dropdownlist on the parent page. I'm refreshing the page with window.opener.location.href ....
but i want only the refresh the dropdownlist on the parent page.
I've got a class that implements IListSource and returns a generic List of ListItem objects (List<ListItem>). in this list one of the ListItems has the Selected attribute set to true.On the web page I have a standard asp:dropdownlist and I set it's datasource to the getList method of my class and databind it.The problem is that the databind seems to loose the selected Item and the first item in the generic list becomes selected.
I am trying to create a form that is made up of controls with values that represent an entity with multiple child entities.
The form will represent a product with multiple properties where the user will then be able to create options with multiple properties which in turn be able to create multiple option-items with multiple properties.
My question is what is the best approach? Can i use ajax to avoid postbacks and having to rewrite the controls to the page? If i dynamically add the controls in the form of table rows or grid rows will the data/control values be available in the code-behind when i submit?
This is an age old question.. the last time i had to do this was .Net 2.0, pre-ajax (for me) and i was forced to recreate all the controls on each post back.
I have 6 form all include jobnumber n in 1st form name creative it is primary key and in remaining form its is foreign key i want to pu drop down aganist job number in remaining form so user can easily access the job number how can i?
I have a formview that when in insert/edit mode, has a dropdowlist and a linkbutton. The linkbutton opens a popup with another formview that allows the user to enter new items that are required to be added to the dropdownlist. When the popup closes, it adds any new items to the dropdownlist options (there may be more than one item added). The purpose is to prevent having to have my users partially add/update a record, go create a new item for the dropdownlist then have to come back and edit again since any new items won't be known until they are needed.
At first, I recieved the 'invalid postback or callback' warning and began reading up on the issue. Though there were several forum posts and web articles, most seemed a few years old so I thought I would find out if there were any subsequent changes that might help me out. I'm using vwd2005/ASP.Net 2.0 and do not have ajax (not available on my corporate web servers). In the page directives, I disabled EnableEventValidation but then I found that while other controls were updating, the value set in the dropdownlist was not and I had to make 2 edits anyway. Since new items in the ddl won't be around when it is rendered, i've read that I can't make use of registerforeventvalidation. ps. i have thought that i could save my viewstate, browse away from the page instead of use a popup, then restore the viewstate, but I'm concerned about being able to update the ddl while retaining the viewstate.
have a dropdownlist (ddl2) which is dependent on the selected value of another dropdownlist (ddl1).I have set the appendatabounditems to "true" for ddl2 and have added a "Please Select" and a "Select All" options. The Options show in the list when the page first loads. When ddl1 is selected the page refreshes and ddl2 is populated, however the "Please Select" and "Select All" options have disappeared.