DataSource Controls :: Add A "-" Or "Please Select" In SQL For Dropdownlist?
Mar 30, 2011
I had a dropdownlist for user to select, i want to insert a "-" or "Please select" at first row of the dropdown list.How can i insert a "-" in sqldatasource ?
if I have three Dropdownlist A, B, C, how can I write a select statement to get data from sql server based on the dropdownlist selected.e.g. if user select dropdownlist A, select * from table where A = dropdownlist A but if user select dropdownlist A and C, then select statment is "select * from table where A = dropdownlist A and B = dropdownlist B or if selected A, B, C.......how can I settle so many choice.
I have dropdownlist of dates and depending on the date that the user selects from list, I would like to filter records that fall between the startyear and finishyear columns in the datasource. (My the problem is that I do not know how to declare the Startyear and Endyear from the query in the code as they appear underlined - probably the BETWEEN syntax is wrong too).
yYear = DropDownList1.Text Using connection As New SqlConnection("Data Source=CHRIS-PCSQLEXPRESS;Initial Catalog=TorGHL;Integrated Security=True") Dim cmd As String cmd = "SELECT BarDetails.*, MenuHeadingId AS Expr1 FROM BarDetails WHERE (MenuHeadingId = 2)" & "WHERE " & yYear & " BETWEEN " & "(" & StartYear & ")" & " AND " & "(" & EndYear & ")" connection.Open() Dim dapubcb As New SqlDataAdapterDim sqlcomm As New SqlCommand(cmd, connection) dapubcb.SelectCommand = sqlcomm Dim dspubcb As New DataSet("BarDetails") dapubcb.Fill(dspubcb, "BarDetails")
I'm using a DropDownList with a data source which successfully populates the list. However, I want one of the items to be selected, namely the one where the value matches the path and query of the current request.
Using the debugger in Visual Studio 2008 reveals that item.Selected becomes true exactly once in the loop, but the rendered select has no option that is selected.
The drop down list is used to determine what search criteria will be used to find an invoice. I tried to set the Select method in the switch statement. I don't understand how to set the Select Method and the select parameters programmatically though . I tried a few different ways but can't make the compiler happy. My ODS is in scope in the code behind. I'm not able to access it's properties though. The BAL resides in a separate project that is a ClassLibrary. I also have a using statement for the ClassLibrary project in the code behind.
I will declarate a attribute, but it gives me an error
This query works fine and returns 1 record from type int:
SELECT TOP 1 DataObjectVersionID FROM tblDataObjectVersionPropertyValueText WHERE PropValue like CAST('00010281' AS ntext) ORDER BY DataObjectVersionID DESC
And when I will declarate a attribute/parameter it gives me an error:
DECLARE @dataObjectVersionId INT SET @dataObjectVersionId = SELECT TOP 1 DataObjectVersionID FROM tblDataObjectVersionPropertyValueText WHERE PropValue like CAST('00010281' AS ntext) ORDER BY DataObjectVersionID DESC
Error message:
Msg 156, Level 15, State 1, Line 2 Incorrect syntax near the keyword 'SELECT'.
i use 2 dropdownlist with 2 object data source first dropdownlist to display departments name using object datasource (field to display DeptName , value of field DeptID)
second dropdownlist to display Employee name but depend on departments (field to display EmpName , value of field EmpID)
how to display employee name in dropdownlist depend on departments name in the other dropdownlist
2 tables
1 table deprtments with column (DeptID , DeptName , DeptDescription)
2 table Employee with column (EmpID , DeptID , EmpName)
I am binding a dropdownlist through stored procedure on page load.
There are tho fields in my databse table City and Class.
in dropdown property i put DataTextField="City" DataValueField="Class"
suppose there are 6 cities in dropdown 3 cities for class A and 3 for class B, see if i select any one city of class A, after select droodown automatically select the first city of class A, and same if i select a city of class B, it auto selects first city of class B.
I had use a combox to let user select staff name and then it will automatically retrive the responsible recommending officer and approving officer to display in other 2 dropdownlist.
my code works fine but when user select staff name each time, the page will reload once to refresh the dropdownlist.
user complaint and don't want the page reload every time, how can i disable the postback? I need to use ajax?
Can i get a multiselect dropdownlist with option to select all and select none. I need it urgently....please send the control to arup.bhattacharya@[URL].
I am trying to populate a gridview when you select the dropdownlist.selected value. I don't want to use the sqldatasource or any other datasource. I am trying my best to achieve this, but didn't succeed till now. One of my friend said that i need to get the selected value from dropdownlist and search for the data in the database using the selectedvalue and populate the dataset and bind to the gridview.
I have 2 dropdownlist controls (ddl1 and ddl2). When I pick an item from ddl1, it will update ddl2. The problem is when I pick an item in ddl2, it always selects the first item in the list. Is it that the ddl2 autopostback causes the first ddl1 to reload and results the ddl2 to be refreshed also? Or I didn't set something correctly?
When I try to use this code in a Form View, I get an error message:
Compiler Error Message: CS0103: The name avgift_namnTextBox is not in the current context ROW: 35
Rad 33: if (dropDownlist.SelectedValue == "Other") Rad 34: { Rad 35: avgift_namnTextBox.Enabled = true; Rad 36: avgift_namnTextBox.Text = string.Empty; Rad 37: avgift_prisTextBox.Enabled = true;
I have been trying for a while to populate a formview when I select an item from the dropdownlist. The dropdownlist is outside of the formview. For some reason, when I select a different item it does not change in the formview. Only the first item of the list shows up. I don't know where I'm doing wrong. I tried many things and suggested informatioin and I still could not get it to work. When I do try to switch I get this error message:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
I would like to know if I can do the following: when I am in insert mode, can I dynamically change the select command of and then display that result in the second dropdownlist based on what was selected in the first dropdownlist.
I would like to include the minimum code to demonstrate what I am trying to do.
I'm building a pretty simple application where a user can enter/modify/delete data from a table. Right now, the only field is month, which I'm storing as an integer (1-12). The actual table has more fields but I'm simplifying for the purposes of this question.I have the entry part. For modifying, I've set up a gridview with an 'Edit' button:
[Code]....
The code is putting the gridview row into edit mode. Now, I want to show a dropdownlist of months so the user can select the new month. Also, I would like the dropdownlist to default to the value in the database. I can't figure out how to bind months to the dropdown list ddlMonth.
DDL3.Items.Insert(0, new ListItem(" please select ", "0"));
I have button in my page that when user click on it insert data into database
Here when users didn't select Item from dropdownlist it insert "please select" ( text that I define for DDL ) into database but I want when users didn't select Item from database it insert NULL in database....
Two ddl inside gridview. on selecting first ddl1 fill next ddl2 by passing selected value as parameter by executing the sqldatasource select command in codebehind.code:
GridViewRow gr = (GridViewRow)((DataControlFieldCell)((DropDownList)sender).Parent).Parent; //find the control in that DropDownList d1 = (DropDownList)gr.FindControl(ddl1); DropDownList d2 = (DropDownList)gr.FindControl(ddl2); SqliaDataSource.SelectParameters.Add("@name", d1.SelectedItem.Text.ToString()); dataView dv=(dataview) SqliaDataSource.select(DataSourceSelectArguments .Empty); Error: There is no source code available for the current location. and Returns null value
I want to have a dropdownlist in the footer row of a gridview. The dropdownlist must be populated with an stored procedure that receives a parameter and has a select. Is that posible?? I think yes but I having problems with the parameters.
[Code]....
The exception says incorrect sintax... but I've changed the procedure for something very simple to solve the problem like select 'hello' or select 1, 'hello' and I'm getting the same problem...
URL.... When I wrote this code in other page with different SP It didn't worked correctly I change SP in new SP I used INSERT code instead of UPDATE now when users didn't select Item from ddl3 it insert 'please select' in table these are my code