Forms Data Controls :: How To Re-bind A Dropdown List Control In A Formview
Oct 20, 2010
I have a formview in which I have a dropdown list that displays a list of owners. In case the list does not have the correct owner for the user I have added functionality for them to add a new owner to the database table that populates the list. I did this by including a textbox and an Insert button in a panel. When the user clicks the new owner insert button I would like to re-databind the dropdown list so that they will see the owner they added and be able to select it.
When I add ddl_owners.databind to my button click code it gives me an error. "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control."
I don't want to re-databind the entire formview because then it deletes all the information on the form that the user has already keyed in.
I am using a dropdownlist inside Edit template of a formview,, the problem it is not saving the value ,, Here is my code : I am only updating the (status)
Is it possible to bind two separated datasources to one dropdown list such that they are both alphabetically sorted and seprated by some sort of line. I know there is a way to insert elemets manually, but I'm not sure of the 2 separate datasources. I've serached this forum and while there were several posts none of them offered any workable solution.
I have created an asp.net customizable gridview where user will be able to add and delete data. Now I face some proplem with this gridview. now I want to add a dropdown list (which is dynamically bind with database) inside the grid. I created code and it bind well. when the page is post back previous selected dropdown list value lose and set to selectedIndex=0; For this reason I used if(!page.Ispostback) and put the dropdown binding code inside this. Here I faced a problem. The problem is when I want to add data inside grid the dropdownlist missin bind. How can I overcome this problem? For your kind observation I given entire code below:
I am attempting to bind data from a dropdown list that was populated from another datasourceID. I've bolded what I believe is relevant to this issue in the code below. But basicly its binding the proper county on the pull down menu but when I hit form submit it dosnt postback that info instead its null.
I have a formview with an insert item template. I have added two dropdown controls that are databound to two different database tables to this insert template. However, when I click the 'InsertQuery' for the Accessdatasource neither of these controls are available as 'Parameter source options'.Out of interest, if I take these dropdown controls out of the formview and put them on the page they then become available to use.
Using Visual Web Developer Express 2010 with ASP.NET 4.0.
I have a FormView and I want to set a default value from the database. I can't get it to bind to the value in the database. My FormView looks like this:
[Code]....
The EditItemTemplate does not even load when I click the edit button on my FormView control, but I don't get an error message either.
I've seen this before, I fixed long time ago and now cannot remember how I did :) My store procedure won't update the record because the sql field 'itemId' is being passed as ZERO always.
How to write code in vb.net to control the Dropdown which is inside FormView EditItemTemplate. FormView named "frmFaultsReg" DetailsView named "lstStatus" Actually what i want to do that there is a textbox inside FormView EditItemTemplate and ItemTemplate to insert Closing date. lstStatus has a value PENDING and CLOSED. If a user select CLOSED from lstStatus then the date textbox named "ClrDateTimeTextBox" should show current date time and to insert into database and if user again selects PENDING from lstStatus then the date textbox should show empty. I think the postback of lstStatus should work but lstStatus is inside the FormView thats why I am unable to hook it.
I am stuck at this point "Displaying a dropdown list of Categories with a --None -- Option. I want the gridview control to display 2 dropdown list one in read-only mode and the other in edit mode. When a record is in read-only mode, the dropdownlist's enabled property will be set to false."When it's on a read-only mode, it doesn't display the selected Category. it shows but the "No Category". When i click on edit to edit or change category, it doesn't display the selected category.
The example is given below( I am reading the book Sams Teach yourself ASP.NET 2.0 by Scott Mitchell. page 628)
<asp:Label ID="UserIdValue" runat="server" Visible="False"></asp:Label> <asp:SqlDataSource ID="picturesDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Pictures] WHERE ([UserId] = @UserId) ORDER BY [UploadedOn] DESC" DeleteCommand="DELETE FROM [Pictures] WHERE [PictureID] = @PictureID" InsertCommand="INSERT INTO [Pictures] ([UserId], [CategoryID], [Title], [Description], [UploadedOn]) VALUES (@UserId, @CategoryID, @Title, @Description, @UploadedOn)" UpdateCommand="UPDATE [Pictures] SET [UserId] = @UserId, [CategoryID] = @CategoryID, [Title] = @Title, [Description] = @Description, [UploadedOn] = @UploadedOn WHERE [PictureID] = @PictureID"> <DeleteParameters> <asp:Parameter Name="PictureID" Type="Int32" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="UserId" /> <asp:Parameter Name="CategoryID" Type="Int32" /> <asp:Parameter Name="Title" Type="String" /> <asp:Parameter Name="Description" Type="String" /> <asp:Parameter Name="UploadedOn" Type="DateTime" /> </InsertParameters> <SelectParameters> <asp:ControlParameter ControlID="UserIdValue" Name="UserId" PropertyName="Text"/> </SelectParameters> <UpdateParameters> <asp:Parameter Name="UserId"/> <asp:Parameter Name="CategoryID" Type="Int32" /> <asp:Parameter Name="Title" Type="String" /> <asp:Parameter Name="Description" Type="String" /> <asp:Parameter Name="UploadedOn" Type="DateTime" /> <asp:Parameter Name="PictureID" Type="Int32" /> </UpdateParameters> </asp:SqlDataSource> <br /> <asp:SqlDataSource ID="categoriesDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [CategoryID], [Name] FROM [Categories] WHERE ([UserId] = @UserId)"> <SelectParameters> <asp:ControlParameter ControlID="UserIdValue" Name="UserId" PropertyName="Text" /> </SelectParameters> </asp:SqlDataSource> <br /> <asp:SqlDataSource ID="maxPictureIDDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT MAX(PictureID) FROM Pictures WHERE UserId = @UserId"> <SelectParameters> <asp:ControlParameter ControlID="UserIdValue" Name="UserId" PropertyName="Text" /> </SelectParameters> </asp:SqlDataSource> <br /> <asp:Label ID="cannotUploadImageMessage" runat="server" Text="The photo could not be added to your album either because you did not specify a file to upload or the file specified was not a JPEG image with the file extension .JPG"></asp:Label> <br /> <asp:DetailsView ID="dvPictureInsert" runat="server" DataSourceID="PicturesDataSource" Height="50px" Width="125px" AutoGenerateRows="False" CellPadding="4" DataKeyNames="PictureID" DefaultMode="Insert" ForeColor="#333333" GridLines="None"> <AlternatingRowStyle BackColor="White" /> <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" /> <EditRowStyle BackColor="#2461BF" /> <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" /> <Fields> <asp:TemplateField HeaderText="Picture"> <InsertItemTemplate> <asp:FileUpload ID="imageUpload" runat="server" /> <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="imageUpload" Display="Dynamic" ErrorMessage="There was no file selected" ValidationGroup="PictureAdd"></asp:RequiredFieldValidator> </InsertItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Category" SortExpression="CategoryID"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CategoryID") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:DropDownList ID="pictureCategory" DataSourceID="categoriesDataSource" runat="server" DataTextField="Name" DataValueField="CategoryID" SelectedValue='<%# Bind("CategoryID") %>' Visible='<%# Bind("CategoryID") %>' AppendDataBoundItems="True"> <asp:ListItem Selected="True" Value="">-- Select Category --</asp:ListItem> </asp:DropDownList> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("CategoryID") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Title" SortExpression="Title"> <EditItemTemplate> <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" Display="Dynamic" ErrorMessage="you must provide a name for the title" ValidationGroup="PictureAdd"></asp:RequiredFieldValidator> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("Title") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Description" SortExpression="Description"> <EditItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Description") %>'
I'm trying to setup a page that will utilize a dropdown list control inside of a grid view control using VS 2005 2.0 version. Everything that I can find online seems to only show the use of the dropdown list control using a data grid. I don't want to use a data grid because it doesn't have the functionality/ power as the grid view control. how I can incorporate a dropdown list control with the grid view control? Here is a copy of my code.
I'm trying to follow this article on cascading dropdown list in a GridView control in edit mode (except I'm using C#) [URL] I keep getting this error message "ProjectID is neither a DataColumn nor a DataRelation for table DefaultView."
I have a web form for handling invoices which has a form view. When I'm in insert item template, I need to have various fields. Some of them are contract number, invoice number, register date and other that are easy to handle. But there is a dropdown list related with a table of prices (the table has price name, price initial payment, number of payments, amount of month fee and so on). So, when the dropdown is selected, fields related with price should get their values from price table, and then the user decides to keep them or type in new values. How can I get it done? Should I use a Dynamic populate extender or type all the code behind using SelectedIndexChanged method to populate price related controls?
For a large fillin form I use the asp.net FormView for the magic databinding to my model. In this model I've a property called Rides (shown below), which exposes a list, which I obviously not want to be replaced entirely. So I made it readonly.
However, this way I can't use the databinding features anymore. Is there a common solution for this problem?
Im tring to get a CMS up and running for work and come to the conclution that the FormView is the way to go.
I have an edit page and would like to have a dropdown list where people pick a "Parent", for my site map/Navigation, from the list instead of needing to know the ID of the Parent. I can do this for my "Add New Page", with no FormView, but when I place it within the formView for my Edit Page the DropDownList1 stops being declared.
So what I need is something like: Parent = Dropdownlist1.serlectedItem.Valu But have no Idea how to achieve this using my FromView, two ObjectDataSource's and the dropdown list.
I have tried to link a asp:Lable text to the value of the Dropdownlist so I can pass that back to the DB with no luck.
The Code behind is as good as blank so may need to add stuff in there but again cant if I cannot declare anything within the For View :(
To insert a new product to table [Products] in DB i have a formview. The formview includes a DropDown list taken from foreign table called [Status]. The table [Status] includes fields ID and Status (Status values are: Inn, Out, Damaged).
When i choose from the DropDown i want the textvalues from Status to be displayed (so far im good) but then i want the [Status.ID] to be inserted in [Products.Status_ID] so the cell value will be 1, 2 or 3. This because [Products.Status_ID] is the foregin key to [Status.ID] so that i have the ability to sort products after Status value later.
But do i really need that foreign key? Do i just complicate it further by doing it this way? Perhaps Status could just be a regular string with no foreign key...?