Dropdown List: Displaying Descriptive Text But Storing Numeric Code?
May 24, 2010
Is it possible to display a list of descriptive phrases (say pulled from a lookup table in a database) but store a code in another table? I'm a beginner at ASP.NET but have some experience with SQL Server. If so, how can I do it?
View 9 Replies
Similar Messages:
Oct 10, 2010
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") %>'
View 2 Replies
May 28, 2010
SELECT *
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME =
'Description'
vw_aspnet_Applications Description
aspnet_Roles Description
vw_aspnet_Roles Description
aspnet_Applications Description
The above query returns only those columns that are named "Description" from the default asp.net membership tables. That is not what I want. Each column has a property called "Description" which allows the developer to provide a detailed description for each SQL field (a.k.a. "column"). Example: aspnet_Membership has a column "Password" which does not have anything in the "Description" property although it should have imo
because without a description, it is not obvious that the password's value happens to be encrypted.
Scenario: Assume that I have a table called Trucks that has data like
Number Odometer ... et cetera
It's schema looks something like this (abbreviated)
COLUMN_NAME Description
Number yyyynnnn where 'yyyy' is year truck was purchased, 'nnnn' is sequential number.
Odometer most recent odometer reading in kilometres
How would I code a SQL SELECT statement in SSMS 2008 to display the schema data such as a column's name, its description text, et cetera? because "description" is such a generic term, I've so far been unsuccesful at locating further information in Google.
View 4 Replies
Mar 25, 2011
I have already stored value of author id in list item value while page loads. but when I change index of drop down list to view author information error is shown. I tried to debug using check points and it seems Sqlreader isn't reading database second time.
Incorrect syntax near '='..
Here is my code
[code].....
View 2 Replies
Jan 8, 2011
How would I go about displaying a databound dropdown list in a property grid, i.e. a dynamic list that can be used to set the value of an individual property?
View 1 Replies
Feb 17, 2011
I got one web page which is developed by using Asp.net. and in that page I have got one tab control which developed by using Ajax control toolkit (tab container). In that tab container i have got three tab pannels. In the first tab pannel have got two drop down list boxes and one image control box. wat I was trying to do is that by using calendar extender control in ajax control toolkit i was trying to display a day in the first drop down list box and month and year in second drop down list box. when user click on image control during run time a small calender will pops up and then user will select the propective date according to there choice and when they have finish selecting the date from the calender a day will display on first drop down list box and month and year will display on second drop down list box.
I was keep trying to do that but i was failed. then i took one test box from the toolbox and i was got success in displaying the user selected date in the text box by using ajax calender extender. How to display that date instead of one textbox into two separate drop down list boxes from which a user can select manual date from drop down list as well and from the calendar as well also when the page loads, the two drop down list boxes must show current date ( by default)
View 1 Replies
Sep 22, 2010
how to get text value of dropdown list box by its index.
i want to read the ddlproject.selectedindex = 0's text and assign it to a variable strProject.
View 2 Replies
Mar 8, 2011
Can these two properties of a dropdown list in ASP.NET be used independently?
I wanted to retrieve a null value when the user selects some text; I couldn't as it retrieves the Text property whenever the Value is null. Eg:
l1 = new ListItem("Cat", null);
Console.WriteLine(l1.Value);
The output is
Cat
In another situation, when both the properties have different strings, I get the string in the Value property when I use the Text property. Eg:
l2 = new ListItem("Cat", "Mouse");
DropDownList ddl = new DropDownList();
ddl.Items.Add(li);
ddl.SelectedIndex = 0;
Console.WriteLine(ddl.SelectedValue);
Console.WriteLine(ddl.Text);
The output is
Mouse
Mouse
View 2 Replies
Apr 22, 2010
First, a user select a country from a dropdown list. The selected item & its value are store in a seesion. Then the user leaves this page.
<asp:DropDownList ID="ddl1" runat="server">
<asp:ListItem Value="US" Selected="True">USA</asp:ListItem>
<asp:ListItem Value="AF">Afghanistan</asp:ListItem>
<asp:ListItem Value="AL">Albania</asp:ListItem>
</asp:DropDownList>
Dim arr(1) as string
arr(0) = ddl1.SelectedItem.ToString
arr(1) = ddl1.SelectedValue
Session("arr") = arr
Later on, the user may come back to the page and change the selection of the country. However, I want the dropdown list to remember the previously selected item and value. The item name and its value are now stored in an array. How do you assign it to the dropdown list as pre-selected.
View 3 Replies
Feb 10, 2010
I'm building a small website using ASP.net/C# and I wanted to know how to implement a simple search feature using a text box and a dropdown.
The datasource is a products table and in the text box I enter the product's name and in the dropdown are the categories. (I have managed to populate the dropdown with the available categories already)
It must follow these conditions:
If both text box and dropdown are blank all products must be listed;
If a category is chosen all products from that category must be listed;
If only text is filled, all products that match are shown;
View 2 Replies
Mar 9, 2011
I have a dropdown control that has a list of names in it called PlayerNameDropDownList_Insert and a textBox called PlayerName.
When I select a name from the dropdown it populates the textbox correctly.However, when the page opens the first name is selected in the dropdown but nothing in the textbox. How can I get the textbox to populate with the value of the dropdown at pageload?
[Code]....
View 4 Replies
Aug 10, 2010
I am very new to coding in asp.net, I've never done anything before, but heres my problem, I have a Microsoft SQL Server 2005 Database, and basically I need to be able to search that database by 3 different things, basically there is tons of data, and I need to be able to search by a member ID, a location, and a group name So basically I wanted a drop down list, with these 3 column names, and than a search box where you can actually type in what you are looking for, than have the results display, I have been trying to do this with gridview, but I can't seem to get it to work correctly
View 14 Replies
Apr 19, 2010
I did my drop down list that get it,s values from database and when run the application it did not work and compiler did not see the code
// aspx
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DDlProductFamily" runat="server"
ondatabound="DDlProductFamily_DataBound"
onselectedindexchanged="DDlProductFamily_SelectedIndexChanged">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DDlProductFamily" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
// cs
protected void DDlProductFamily_SelectedIndexChanged(object sender, EventArgs e)
{
using (SqlConnection Con = Connection.GetConnection())
{
SqlCommand Com = new SqlCommand("SelectThumbByProductFamily", Con);
Com.CommandType = CommandType.StoredProcedure;
Com.Parameters.Add(Parameter.NewInt("@ProductCategory_Id",
DDlProductFamily.SelectedValue.ToString()));
SqlDataAdapter DA = new SqlDataAdapter(Com);
DA.Fill(dt);
DataList1.DataSource = dt;
DataList1.DataBind();
}
}
View 3 Replies
Sep 12, 2010
I have some dropdown list boxes that I need to fill with data from a database but I also need the first option to be "Show All"... So I need to combine using a datasource and manually adding an item to the top of the list. I have tried two different ways with no luck:
1. with the appendDataboundItems = true, on aspx page, and below code in codebehind:
//lstClass.Items.Clear();
View 9 Replies
Nov 13, 2010
I have a text box placed inside a gridview(template) . I need to update its value by a dropdown list event (Selected Item Changed event) placed in the same gridVew. But The problem is that , I need to update the text box of the same row the dropdown list (whose textChange Event haas been fired)
[code]....
View 1 Replies
Apr 18, 2010
i have set the type of a column in a table numeric(6,2) but when i insert a value above 9999,99 i get the error
"Arithmetic overflow error converting numeric to data type numeric."
Do you know whats wrong??
ofc thats all through visual studio for an asp site thats why im posting here
View 4 Replies
Oct 20, 2010
I am using a list view with page size 10 and added a numeric data pager for paging.everything is working fine but how i can hide the page number shown below when the data in list view is less than 10 and show it only data is greater than 10.
View 1 Replies
Aug 3, 2010
I'm a complete novice to ASP.Net embarking on a charity work for a primary school in Africa to create a simple website. The website should have a webpage that users can upload pictures that is stored and displayed as thumbnails. Which can be click on to show the picture in its actual size.
I've used masterpages to create a consistent look across all pages. On the gallery page, I have a textbox and a button which are yet to be programmed.
View 9 Replies
Apr 21, 2010
i am using one text box to enter phone number,bt here is some problem. if user enters other than Numeric ,the text box should show the error. how can i do that?
View 10 Replies
Nov 3, 2010
I have 2 drop down lists.I have a very simple dropdown list #1 that diplays a title and holds an id value which is a GUID.I know it is getting this value and sending this value as I tested sending it to a label.I have the dropdown list #1 to autopostback to dropdown list #2 that "Is supposed to get" another title and value based on the GUID value of the first dropdown list. for some reason it wont return anything. I have done 100's of these but never based off a guid value.I assume the value needs to be converted to guid before selecting it in the second dropdown list.How can I do this? or is there something I am missing?
View 9 Replies
Mar 17, 2010
I was wondering if anyone had a tutorial or overview of the best way to store html in a MS SQL database, and then calling it back up and displaying it and should I save the decoded html in ntext?
View 5 Replies
Aug 30, 2010
how to handle html and scriptswhat . if I build my own CMS? Isn't it inevitable that I'll want to store html code, possibly scripts, and almost certainly apostrophes and special characters, and then display them again.
What's the best way to do this, since I wont want to display the encoded html, but the html itself.
Would it be to encode everything then when I want to actually display the html, decode it, but everywhere else, keep it encoded?
I'm just trying to think of all the scenario's that I could come across when I accept user input where I don't know what they could be typing in. What if I WANT the user to be able to display html? Is it possible to decode only some tags but leave all other tags encoded?
View 10 Replies
Jan 23, 2010
Me with C# asp.net, how can I validate a text box such that it should accept only numeric values and -
View 6 Replies
May 5, 2010
I want to achieve 30 numeric 2 decimal point text box. how can I achive this
View 4 Replies
Feb 15, 2010
First of all im new to asp.net and am in the process of learning it.
Heres my problem, i am receiving this error when submitting the form: "Arithmetic overflow error converting numeric to data type numeric"
And it halts at command.ExecuteNonQuery();
Input form:
[Code]....
Code Behind:
[Code]....
Stored Procedure:
[Code]....
View 11 Replies