on my page: two sqldatasources one has the sqlexperession:
SELECT DISTINCT [Skil] FROM [UsersView]
UNION
SELECT 'Alles'
the other one :
SELECT [UserName], [Afdeling], [Skil], [RoepNaam] FROM [UsersView]
the first source is bound to a dropdown list. witch I want to use for filtering.
the second to a gridview.
the code for the dropdownlist selectedindexchanged is:protected void SkillDDL_SelectedIndexChanged(object sender, EventArgs e)
{
if (SkillDDL.SelectedValue.ToString() == "Alles")
{
SqlDataSource3.FilterExpression = "";
}
else
{
SqlDataSource3.FilterExpression = "Skil = '" + SkillDDL.SelectedValue + "'";
}
}
The strange thing is that initially 'Alles' is selected in the dropdown list and I see all the records. then I select an other value in the dropdownlist. and I get the filtered records, like I would expect.
then when I select 'Alles' again I keep my last selected records in view. I would expect that the filter is now an empty string and I would get all the records again. what do I do wrong?
I'm not sure exactly how the FilterExpression works. I have a sqldatasource, stored procedure, and GridView. My stored procedure basicly a select statement to populate my gridview, it included the fields I want to filter on. In my codebehind file I build a WHERE Clause based on the entries a user makes. Then I add the my FilterExpr variable to the SqlDataSource1.FilterExpression = FilterExpr. My SqlDataSource has a number of control parameters that match the textboxes a users enters into. My question, I guess is does my stored procedure need the variables matching my controlparameters for my sqldatasource? Or how does this work? My GridView is returning all rows no matter what I enter into the filter textboxes (first, last, etc...) MY SQLSDATASOURCE <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="ClientSearch" SelectCommandType="StoredProcedure"> <FilterParameters> <asp:ControlParameter ControlID="SearchLastName" Name="LastName" PropertyName="Text" ConvertEmptyStringToNull="true" /> <asp:ControlParameter ControlID="SearchFirstName" Name="FirstName" PropertyName="Text" ConvertEmptyStringToNull="true" /> <asp:ControlParameter ControlID="SearchEmail" Name="Email" PropertyName="Text" ConvertEmptyStringToNull="true" /> <asp:ControlParameter ControlID="SearchAddress" Name="Address" PropertyName="Text" ConvertEmptyStringToNull="true" /> <asp:ControlParameter ControlID="SearchComment" Name="Comment" PropertyName="Text" ConvertEmptyStringToNull="true" /> </FilterParameters> </asp:SqlDataSource>MY CODEBEHIND Dim FilterExpr As String If SearchLastName.Text = "" And _ SearchFirstName.Text = "" And _ SearchEmail.Text = "" And _ SearchComment.Text = "" And _ SearchAddress.Text = "" Then lblMessage.Text = "You didn't enter any search parameters. Please try Again." Me.GridViewSearch.DataSourceID = "" Exit Sub Else Me.GridViewSearch.DataSourceID = "SqlDataSource1" End If FilterExpr = "" If SearchLastName.Text <> "" Then FilterExpr = FilterExpr & "LastName Like '" & _ SearchLastName.Text & "%" & "' AND " End If If SearchFirstName.Text <> "" Then FilterExpr = FilterExpr & "FirstName Like '" & _ SearchFirstName.Text & "%" & "' AND " End If If SearchEmail.Text <> "" Then FilterExpr = FilterExpr & " Like '" & _ SearchEmail.Text & "%" & "' AND " End If If SearchComment.Text <> "" Then FilterExpr = FilterExpr & "[Comments] Like '" & "%" & _ SearchComment.Text & "%" & "' AND " End If If SearchAddress.Text <> "" Then FilterExpr = FilterExpr & "[Address] Like '" & "%" & _ SearchAddress.Text & "%" & "' AND " End If If Right(FilterExpr, 4) = "AND " Then FilterExpr = Left(FilterExpr, Len(FilterExpr) - 4) End If Try Me.SqlDataSource1.FilterExpression = FilterExpr Me.SqlDataSource1.DataBind() Me.GridViewSearch.DataBind() Me.lblMessage.Text = Me.SqlDataSource1.FilterExpression Catch objException As SqlException Dim objError As SqlError For Each objError In objException.Errors Response.Write(objError.Message) Next End Try End Sub MY SPROCGO ALTER PROCEDURE [dbo].[ClientSearch]
AS SELECT C.ClientID, C.FirstName, C.LastName, A.Address, C.Comments, C.EMail FROM tblClient C INNER JOIN tblClientAddresses A ON C.ClientID = A.ClientID
I have a SQLDatasource control on a web page. It is the datasource for a gridview control.I want the gridview to show all jones if the FirstName textbox is left blank or empty. Right now I have to put a % in the FirstName textbox to get what I want. If I make the FirstNameTextBox empty or remove the % from the FirstNameTextbox it returns all the names in the database no matter what the last name is.How do I get it to work without having to use the % in the FirstName Textbox? THANKS!FilterExpression="LastName LIKE '%{0}%' and FirstName LIKE '%{1}%'"><FilterParameters> <asp:ControlParameter ControlID="LastNameTextBox" Name="LastName" PropertyName="Text" DefaultValue="" /> <asp:ControlParameter ControlID="FirstNameTextBox" Name="FirstName" PropertyName="Text" DefaultValue="" /></FilterParameters> Last Name: Jones___________First Name: %_____________FILTERBUTTON GridviewLast Name First NameBob JonesBill Jones
How does one programmatically retrieve the results from a sqldatasource that has had a filterexpression applied to it? Let me elaborate, here is my code: SqlDataSource1.FilterExpression = "MenuType = 'myfilteredvalue'" Dim _dv As DataView = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), System.Data.DataView) _dv.Table.TableName = "Menu" Dim ds As New DataSet("Menus") ds.Tables.Add(_dv.Table.Copy()) 'Add relation: ParentID under MenuID Dim relation As New DataRelation("ParentChild", ds.Tables!Menu.Columns!MenuID, ds.Tables!Menu.Columns!ParentID, True) relation.Nested = True ds.Relations.Add(relation) What I'm doing is, I have a sqlDataSource that pulls all the data from my DB. With this data in the sqlDataSourceSource, I want to then populate an XMLDatasource (via a dataset) with only the records I need, i.e. the filter. However, after I apply my filter above, the sqlDataSoruce still contains all the records. I thought maybe if I did a sqlDataSource.Bind() after my SqlDataSource.FilterExpression, but that didn't do anything either.In laymans terms:I want to say something like: dataset = sqldatasource.filter(my filter expression).
I am using the FilterExpression of an SqlDataSource object to filter the rows of a gridview. It works with searching text values but I cannot for the life of me figure out to get it to work with dates. The following is what I do for character searches: SomeDataSource.FilterExpression = fieldToSearch + " LIKE '%" + SearchTextBox.Text + "%'"; This works. However when I try to search for dates using the following it doesn't work (startDate and endDate are DateTime objects):SomeDataSource.FilterExpression = fieldToSearch + " BETWEEN #" + startDate.ToString("yyyy-MM-dd") + "# AND #" + endDate.ToString("yyyy-MM-dd") + "#";// or SomeDataSource.FilterExpression = fieldToSearch + " = #" + startDate.ToString("yyyy-MM-dd") + "#";// or SomeDataSource.FilterExpression = fieldToSearch + " = #'" + startDate.ToString("MM/dd/yyyy HH:mm:ss") + "'#";
I have wrote some codes as follows: Dim sqldatasource3 As New SqlDataSource sqldatasource3.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("aspnetConnectionString").ConnectionString sqldatasource3.SelectCommand = "select stepno,steppersontype,stepname,steptype,fchoice,fforward,schoice,sforward from flow " sqldatasource3.FilterExpression = "stepname = '" & GridView1.SelectedRow.Cells(4).Text.Trim & "'" sqldatasource3.DataSourceMode = SqlDataSourceMode.DataSet Dim dv As DataView = sqldatasource3.Select(DataSourceSelectArguments.Empty()) dv.RowFilter = "stepname = '" & GridView1.SelectedRow.Cells(4).Text.Trim & "'" but i found the filterexpression didn't work. No matter what value GridView1.SelectedRow.Cells(4).Text.Trim be,sqldatasource always return the whole dataset.I wanna know where these code are wrong? Can anyone help?
I facing a problem when i want to modified the sqldatasource.filterExpression while trigger sqldatasource.selecting event. 1 Protected Sub SqlDsProduct_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) 2 Dim SqlDsProduct As SqlDataSource = CType(CompleteGridView1.DetailRows(0).FindControl("SqlDsProduct"), SqlDataSource) 3 SqlDsProduct.FilterExpression = Session("filter") ' filter i add up after user press search button 4 End subActually i'm using the CompleteGridview, which i downloaded from the web. the "SqlDsProduct" i reffering to is inside the CompleteGridView1. I'm using complet grid view because i want the hierarchy look for the gridview. So please help me how i gonna change the filter expression of the 2nd sqldatasource inside detailsTemplate of the completeGridview. Thank you. best regardvince
I have a CheckBoxList which is bound to a SQLDataSource and populated with a list of courses. Under this I have a calendar control which is bound to another SQLDataSource control. When the page is first loaded this is empty because no courses are selected. I'd like it so that the user can select one or more course from the CheckBoxList and the appropraite events are loaded into the calendar control bound to the second SQLDataSource. I've tried using FilterExpression but this seems to work on the basis of a complete resultset being loaded and then filtered-out using the FilterExpression. I'm starting with no records and would like to Filter-In data from the database. Is this possible using FilterExpression?
I have a some search components to filter a GridView follows: <asp:DropDownList ID="ddFilterType" runat="server" ToolTip="Select field to search"> <asp:ListItem Selected="True">(ALL)</asp:ListItem> <asp:ListItem>SKU</asp:ListItem> <asp:ListItem>Vendor Name</asp:ListItem> <asp:ListItem>Item Name</asp:ListItem></asp:DropDownList><asp:TextBox ID="txtSearchFilter" runat="server"></asp:TextBox><asp:LinkButton ID="btnSearchFilter" runat="server">Filter</asp:LinkButton> and C# code as follows: protected void Page_Load(object sender, EventArgs e){ if (IsPostBack) { if (ddFilterType.SelectedValue != "ALL") { dsItems.FilterExpression = (ddFilterType.SelectedValue = txtSearchFilter.Text); gvItems.DataBind(); } else { gvItems.DataBind(); } }} But when I run the search, I get:Exception Details: System.Data.EvaluateException: Cannot find column [the value in txtSearchFilter.Text]. How should I do my C# syntax to get this to work? Also, I would like to add further logic to check if the field is not the SKU field and have my expression do a LIKE expression instead of checking for equality. Any help with this is much appreciated. Marc
I have a filter expression and I have 2 data types one is an int and the other is a date format. I want to setup 2 textboxes to search for either the int or the date. I have the FilterExpression setup as follows: FilterExpression="PROJECT_CODE = '{0}' or PROJECT_DATE L= '{0}'"<FilterParameters> <asp:ControlParameter ControlID="TextBoxProjectCode" Name="PROJECT_CODE" PropertyName="Text" Type="Int16" /> <asp:ControlParameter ControlID="TextBoxProjectDate" Name="PROJECT_DATE" PropertyName="Text" /></FilterParameters> I can take out one or the other and run the search and return results, but can not do it with both. Is there a way to do this and what do I need to do to make it work?
I am trying to filter some results using the FilterExpression Property of the SqlDataSource. I have multiple drop down lists with different filtering options. I am trying to change the filter that is applied to a gridview. Something like this example... http://blogs.vbcity.com/mcintyre/archive/2006/08/17.aspx Here is some of my code..Private Sub ApplyFilter() Dim _filterExpression As String = "" If (Not DropDownList1.SelectedIndex = 0) And (DropDownList2.SelectedIndex = 0) And (DropDownList3.SelectedIndex = 0) Then _filterExpression = "CategoryName = '{0}'" End If Me.SqlDataSource1.FilterExpression = _filterExpression End Sub Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged ApplyFilter() End Sub But this doesn't seem to work. The FilterExpression doesn't keep the value. I am looking for a way to dynamically change the FilterExpression. Any Ideas or Suggestions?? Thanks.
Hi. Is there a way to convert a smalldatetime value to a year value (1/1/2001 -> 2001) in this case? I tried year(thisIsSmalldatetimeField) and datepart(yyyy, thisIsSmalldatetimeField) Dim FilterExpression As String = String.Concat("thisIsSmalldatetimeField=" & DropDownList.SelectedValue & "") mySqlDataSource.FilterParameters.Clear() mySqlDataSource.FilterExpression = FilterExpression
Hello, I have a Repeater control getting data from a SqlDataSource.The SqlDataSource uses a stored procedure which accepts a input parameter with the name "sort" (@sort). How do I use the FilterExpression with FilterParameter for defining the input value for the stored procedure ?The input value comes from an asp:QueryStringParameter.Or can the FilterExpression only be used with SQL Statements defined directly (as for defining the where clause) ? I guess the best way is to use the FilterExpression soo the data is cached in the Dataset which is needed/required when using FilterExpression.Alternativly I could use the SelectParameter instead FilterParameters, but I guess the data wont be cached then.Anyone who can help me and guide me in the right direction ? Best regardsMartin
What is the C# code I use to do this? I'm guessing it should be fairly simple, as there is only one row selected. I just need to pull out a specific field from that row and then insert that value into a different SqlDataSource.
i am using visual web developer 2005 with SQL Express 2005 with VB as the code behindi have one database and three tables in itfor manipulating each table i am using separate SqlDataSource() is it sufficient to use one SqlDataSource() for manipulating all the three tables ? i am manipulating all the tables in the same page only please help me
I have an asp:sqldatasource which is bound to a gridviewIn addition to this I would like it to a) see if there is a specif row/ item in it (ie item_id = 10 for any of the rows it has received) as I conditionally want to show another item outside of the gridview subject to if it is in the gridview or notb) show the sum of all the values within a certain column of returned rowsMany thanks
How do I get the result of this select into a variableDim sqldsFindUserId As SqlDataSource = New SqlDataSource sqldsFindUserId.ConnectionString = ConfigurationManager.ConnectionStrings("bluConnectionString2").ToString sqldsFindUserId.SelectCommandType = SqlDataSourceCommandType.Text Dim myUserIdCmd As String = "select pkUser from tblUsers where strDisplayName='" + myDisplayname + "" sqldsFindUserId.SelectCommand = myUserIdCmd ' The result of this select statement is to be stored in a variable, how do I do it?
hi all, in all my 2.0 learnings and books i keep coming across the page element <asp:sqldatasource>. I have always (in 1.1) used server side connections and adapters to bind my Sql datasets to any control needed. Now that im learning 2.0 im finding it difficult to understand using control on the page to bind my data. Can someone explain the benefits of using this data source? Ideally i would like to keep my data access layer separate from my presentation layer but i'd really like to understand why this method seems so popular. thanks in advance, mcm
Hi, I am new to ASP.NET 2.0 and I am trying to use VWB to bind my web site to a SQL Express edition. I used SQLDataSource to specify the .mdf file so I can connect to my tables but when I click on the advanced button to generate the Insert, Update, Delete SQL I find it grayed out and it cannot be clicked. I looked into several tutorials online and I couldn't find the problem, can anyone explain what I am missing or doing wrong? Any suggestion is very appreciated. Thanks
SELECT * FROM [CONTACTS] WHERE @ddl_value LIKE '%@txt_value%'
Why doesn't this not working I am using SQLdatasource control to bind a gridview If my query is wrong then what might be the correct one to work with like operator in the sqldatasource Can any ony help me!
Hello All, I have quick question .. In my aspx page i have gridview and Sql DataSource object as you can see <asp:sqldatasource id="SqlDataSource1" runat="server" ></asp:sqldatasource>
<asp:gridview id="GridView1" runat="server" allowpaging="True" allowsorting="True" autogeneratecolumns="False" datasourceid="SqlDataSource1"> <columns> <asp:boundfield datafield="breakdownid" headertext="breakdownid" insertvisible="False" readonly="True" sortexpression="breakdownid" /> <asp:boundfield datafield="ticketno" headertext="ticketno" sortexpression="ticketno" /> <asp:boundfield datafield="systemtype" headertext="systemtype" sortexpression="systemtype" /> <asp:boundfield datafield="break_date" headertext="break_date" readonly="True" sortexpression="break_date" /> <asp:boundfield datafield="subject" headertext="subject" sortexpression="subject" /> <asp:boundfield datafield="status" headertext="status" sortexpression="status" /> <asp:boundfield datafield="prioritylevel" headertext="prioritylevel" sortexpression="prioritylevel" /> <asp:boundfield datafield="mobiletype" headertext="mobiletype" sortexpression="mobiletype" /> </columns> </asp:gridview> In codebehind file i call a function to get data from database. what i want is to bind the result to the sqlDataSourse not the gridview. I need to have the SqlDataSourse thier.. Any help please
Sub Page_load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Page.IsPostBack Then Dim objReader As New Dynamic.Reportsdemo SqlDataSource1 = .objReader.Get_Tickets(1, 0, "all")
I am trying to get record from a table and verify it with a textbox i have a sqldatasource. i have a text box called txtEmail and this is my Select command. how can i get this working if its possible ? something like txtEmail.text = SqlDataSource1.Secect then ... my code. (i dont know if this a correct way to do this) <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:imacstestConnectionString %>" SelectCommand="SELECT FROM [t_CustomerAcct]"
hi all,i am using sqldatasource for gridviewso that i can edit and update any row at the same place ..... and not to write any code for that....now later on if i wanna change the selectcommand of that sqldatasource how can i ? so that the edit and update will be same as it was....
Hi, I'm trying to go through a checkbox list and inserting them into a database using a sqldatasource with the following code:For Each li As ListItem In Locations_Checkbox.Items If li.Selected = True Then
Dim DataSource2 As SqlDataSource = CType(InsertProgrammeLocations, SqlDataSource) DataSource2.InsertParameters.Add("ProgrammeID", li.Value) DataSource2.Insert()
End If Next When more than one checkbox is ticked, I'm getting the error 'The variable name '@ProgrammeID' has already been declared'. How do I close or reset my Datasource before I try and use it again? Thanks for your help
Hi, I want to know when to use an sqlDataSource object because I used to populate for example a listBox control in visual studio net 2003 from AQLK server database by using a connection object, command object, dataAdapter object and a DataSet object. I discovered if I use sqlDataSource object (using visual studio net 2005) ,all I need is to write the connection string and a Select statement as properties for that sqlDataSource, so why to use the above mentioned objects(connection,command,adapter,dataset) while I can access any database in sql server through the use of sqlDataSource? I appreciate if you can explain to me the difference and when to use an sqlDataSource thx
Hi, I have an application w/ n-tier design so I've never used the SqlDataSource up to this point but having to do my own sorting for GridViews is not something I want to keep dealing with. I'd like to take advantage of some of the packaged features too. My question is: are there any purists out there who opted to use SqlDataSource. If so, what do you think about it? It's nice that SqlDataSource makes things simple but having data classes and dealing w/ exceptions in those classes certainly make an application pretty robust. Should I entertain the idea of using SqlDataSource or stay as a purist and keep doing things the old fashioned way?