I am using asp.net with vb.net code behind. I have a database that contains a list of names. I use an asp:dropdownlist databound with SqlDataSourceID and it works fine to get the list from the database to the dropdownlist and display it.
However, I want to use the dropdownlist to also allow the user to add unique values to the dropdownlist and therefore edit the database.
How do I do this? I cannot enter unique values in the dropdownlist now. Below is the asp snippet.
Thanks for the help.
<asp:DropDownList ID="OEMDropDownLst" runat="server" AutoPostBack="true"
CssClass="NwDrpDwnFmt" DataSourceID="SqlDataSource1" DataValueField="CustomerName"
AppendDataBoundItems="True">
</aso:DropDownList>
If I understand correctly you want users to type directly into your dropdownlist? As far as I know that can't be done. If you want users to add new options to that dropdownlist then you have to create the fields needed and have an update button so then you rebind the dropdownlist after changes have been saved.
</aso:DropDownList></asp:DropDownList> Spelling mistake brother.
Related
How can I format the gridview in asp.net on run time. Using the autoformat template?
For example, there is a gridview control, and there is dropdown list, inside the dropdownlist are the autoformat templates.
And I need to change the design of the gridview by just choosing from the dropdown list or is it even possible?
First of all, read carefuly GridView Examples for ASP.NET 2.0: Formatting the GridView. Then, on your dropdown list OnSelectedIndexChanged event, you can format which cell or column you want.
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="DropDownList1_OnSelectedIndexChanged">
Accessing a DropDownList inside a GridView
Basically, the codes I have is from here : http://ranafaisal.wordpress.com/2009/02/17/dynamically-adding-removing-textboxes-in-aspnet-repeater/
However, the thing is that, I will need a dropdownlist with textboxes. The purpose of having dropdownlist is to allow users to select their country of origin. They have the option to Add or Remove the particulars they have entered before.
This is my error message:
'ddlName' has a SelectedValue which is
invalid because it does not exist in
the list of items. Parameter name:
value
This is my dropdownlist code inside a repeater in Default.aspx
<asp:DropDownList ID="ddlName" runat="server" SelectedValue='<%# DataBinder.Eval(Container.DataItem, "ddl") %>'></asp:DropDownList>
The codes behind is exactly the same as the link I provided.
Points to note: There is no database involved.
Please not tell me to google or anything because I have been googling for the past few hours, to no avail. I definitely have googled enough, and tried the solutions given by others before posting here. I am pretty much at my wits end
To add-on, I cannot even start-up my application because of the dropdownlist problem.
The problem is you need to fill the DropDownList possible options before you set the selected value which you are trying to do inline with the Eval. I would switch it to use the OnDataBinding of the DropDownList and do what you need there.
Example:
<asp:DropDownList ID="ddlName" runat="server" OnDataBinding="ddlName_DataBinding" />
protected void ddlName_DataBinding(object sender, System.EventArgs e)
{
DropDownList ddl = (DropDownList)(sender);
// Fill your ddl here (eg. ddl.Items.Add("abc", xyz");
// Make sure the value you are going to set the selected item to has been added
// Now set the selected value since it will now exist.
ddl.SelectedValue = Eval("ddl").ToString();
}
My goal is to allow the user to enter order header and detail data and have it all save with a single button click, in one transaction so the save is all or nothing.
For example:
Tables:
OrderHeader:
Id,
CustomerId,
Comments,
OrderDate,
OrderLine
Id,
OrderId FK => OrderHeader
ProductId,
Quantity
Markup (abbreviated):
<asp:FormView ID="uxFormHeaderInfo" runat="server" DataSourceID="headerDataSource">
<InsertItemTemplate>
<%--Header Fields--%>
.....
<asp:GridView ID="uxDetails" runat="server" DataSourceID="detailsDataSource">
<%-- Markup --%>
.....
</asp:GridView>
<asp:Button ID="uxSave" runat="server" CommandName="Insert" />
</InsertItemTemplate>
</asp:FormView>
In the page i'd have FormView control that will contain the edit fields for CustomerId and Comments, also i'd have a nested gridview or listview that I could add line items to. The FormView and gridview controls would most likely be linked to independent datasource controls. What I want to happen is for the user to enter the header info and the line items and click save just once at the bottom of the screen.
Is this even possible using the LinqDataSource or ObjectDatasource objects? If so could you point me to a good example that shows how to do this in master/detail style insert that hits 2 or more tables with a single button click? Thanks in advance.
[Edit]
After reviewing feedback and searching around on this subject, I've concluded that datasource controls are just the wrong tool for the job. Since they can't really handle a case as pedestrian as this, it really does call into question their usefulness IMHO. So much for the new way...
I don't think this is going to work with a DataSource. At least not that i know of.
I would handle the Save operation myself. In the Click event of your save button read the values the user has entered, encapsulate it in a transaction and call your business functions.
There is no asp:HiddenField that can be used in a GridView so I was wondering what would work similar to this.
My reasoning for wanting this is I have a ButtonField that triggers an OnRowCommand. From there I can figure out which row was selected, but I cannot retrieve the text value from the ButtonField to see the data that was bound to it (through DataTextField).
My solution to this was to have a BoundField and just retrieve the text value from it instead, since I already knew which row was selected. This worked, but I need it to be hidden.
Someone suggested using a HiddenField nested within a TemplateField, but I had troubles retrieving the text value from that HiddenField. Is there some way to access the control within the TemplateField to get the text value of the HiddenField?
If anyone has any suggestions for alternatives that would be great as well.
Thanks,
Matt
You can use a template field with the commandArgument equal to the the ID of the record/row.
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="false"
CommandName="SomeCommand" Text="Button" CommandArgument='<%# Eval("SomeID") %'></asp:LinkButton>
</ItemTemplate>
Then, in the row command handling event you can get that value by e.CommandArgument
You can use the DataKeyNames property on the Gridview.
gridView.DataKeyNames = { "values", "you", "want "};
and then you can access them like this:
gridView.DataKeys[rowId].Values["value"];
is it possible to add another ID column, as a unique representative for a record(row) ? That particular ID column can be set with style: display=none in order to hide it, but still the ID is inside the HTML form.
and then you can retrieve the value of that particular ID column to be processed further.
hope this helps,
hadi
pretty much what the title says.
I am using an Ajax Drop Down as illustrated here:
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/DropDown/DropDown.aspx
using linkbuttons ... is there a way to limit to list?
Thank you.
Edit: I think it was VB 6 maybe that you could select "LimitToList" in a drop down. Meaning the user can only select the values in the drop down and not enter his own data.
Since you're extending a textbox, I think the best option would be to attach an event listener that voids keypresses, you could do this in the ASPX:
<asp:Textbox id="txtFoo" onkeypress="return false;" runat="server"/>
Or, in the code behind:
txtFoo.Attributes.Add("OnKeyPress","return false;");
This will prevent a user from typing in the textbox, essentially creating the effect you want.
A bonus side effect is that a user is allowed to free type an entry if javascript is disabled and the dropdown extender doesn't work.