DataSource Controls :: Add More Than One Default Value For ControlParameter?
Jan 4, 2011
Some of you might know that I am currently working on a simple blog (thread with full details here). There is a slight problem however ! After achieving the post filtering, the blog doesn't show any posts, unless; I click on of the categories. I was hoping that the blog would show ALL posts at first, and THEN if a user clicks a Category, the filtering would occur. So I went over the code again, and there was this:
[Code]....
The DefaultValue="0" caught my eye, so I changed the number to "1" and I got all the posts in the [ General ] category, I tried "2" and I got the posts from the [ Programming ] category ..etc So I was thinking how I'd go about solving this problem, because (initially) I want the posts from ALL categories to show. Is it possible to add more than one defaultValue ? for example: DefaultValue = "1,2,3"
I have tried the above and it gave me errors, so obviously it doesn't work that way, but is there another way of adding more default values ? Or could you think of a different way to make all the posts show ?
I have a gridview connected to sqlDS and a dropdown Dropdown contains a selection Last 30 days, 60, 90,180 etc... How to write a Where Statement that reflects this? If I want to view the last 60 days of records
WHERE RecordDate >= TodaysDate - 60 days, but as a parameter WHERE RecordDate >= TodaysDate - @SelectedValue days
Which currently uses a 2 character code from a radio button list as its value. It is used as a parameter for a stored procedure. Somewhere else on the page I have a combobox called cbTripPick with that 2 character code embedded within its text property. I wish to use that 2 character substring as the control parameter instead of the above. Can I do something like this ?
<asp:controlParameter Name="WH" ControlID="cbTripPick" PropertyName = "some function or expression or eval that will give me the 2 char. value from the cbTripPick control" DefaultValue="DL" Type="String" Size="2" />
Is it possible to declaratively set the propertyname to some dynamic expression which will get me what I want? Or should this all be done programmatically?
I am having a problem with using A Gridview SectedIndex or value in a sql ControlParameter. When I select the row it does what I need it to except it shows that there is no data.
but if I add Default Value of 1 the data shows up, but it needs to read from the Gridview.
[Code]....
I even added sqlDataSource.DataBind() in the SelectedIndexChanged Event to see if that would fix it but - No! I used it with a DropDown and it worked only when I use AutoPostBack = true of course.
I am working on a project and I need to use Master/Details view, the problem is everything works fine except when I place the Master (gridview) and Details(FromView) in different content holder.
The error I get is:
Could not find control 'GridView1' in ControlParameter 'ID'.
Description:
An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Could not find control 'GridView1' in ControlParameter 'ID'.
I have an ObjectDataSource with a number of parameters. These parameters are binded in my FormView EditItemTemplate and the ItemTemplate. My Stored Procedure column names in my ItemTemplate are different to the Bind properties used in the EditItemTemplate. This is obviously throwing an exception when I update a record.
Instead of using Bind("Columne Name") in my EditItemTemplate how do I use a ControlParameter to reference a TextBox in the EditItemTemplate?
I may be wrong but I'm trying to use the PropertyName=Controls but i do not know how to reference the Textbox in the EditItemTemplate.
i'm using Relational Tables and during Edit, my Drop Down list is a lookup column from the Master table, but when i try to edit it works and shows the records the only problem is that when i udpate, i get the error (Can't find control DDLSongs (my drop down control) in @AlbumID Parameter) below is the code for ref.
i have two tables (Albums,Photos).befor i want insert a record in a Photo table i must select name of album so i create a user control that have a dropdownlist and a datasource(Albums table) until when i select a name of album put AlbumID in a Property(SelectedValue) when i use this user control in details view in edittemplate i have an error
--->error could not find control 'SelectedAlbum' in ControlParameter 'AlbumID' my code id:
public partial class Admin_SelectedAlbum : System.Web.UI.UserControl { public string [COLOR="Red"]SelectedValue[/COLOR] { get { return DropDownList1.SelectedValue; } } protected void Page_Load(object sender, EventArgs e) {.........
how does AlbumID (photo table) set with value of property(SelectedValue) of Usercontrol?
I have a <asp:Parameter Name="Person_ID" Type="String" />. My Updatecommand contains, among other things: Person_ID = @Person_ID. That's all fine.
In my code behind, how to I say that I don't want to specify a value for this parameter, but rather want it to use the default value (which in this case is NULL?)
Or rather than telling it to use the Default value, is it possible to set it to Null? I tried setting the value to Null, but the sql code that got generated was Person_ID = "NULL", which of course, is wrong. How do I get it to generate Person_ID=NULL?
Everything was good before I bumped into the problem when declarative binding (SelectedValue='<# Bind("SvcCluster_Id") >') produced the error, because value has not been found in the list. So i moved binding to the code:
protected void frmConfigEdit_DataBound(Object sender, System.EventArgs e) { if (frmConfigEdit.CurrentMode == FormViewMode.Edit) { var svcCluster_id = DataBinder.Eval(frmConfigEdit.DataItem, "SvcCluster_id"); var ddlCluster = (DropDownList)frmConfigEdit.FindControl("ddlCluster"); if (svcCluster_id != null && ddlCluster.Items.FindByValue(svcCluster_id.ToString()) != null) { ddlCluster.SelectedValue = svcCluster_id.ToString(); } } }
But now seems like this happens later than ObjectDataSource tries to access frmConfigEdit$ddlCluster...
How to manage this?
I wouldn't like to move everything to the code (I mean creating Control parameters, etc)
p.s. Oops, actually it works ok for DataBound event! Sorry.
I've created a table with a userId column of type uniqueidentifier, and have set that column as the primary key. In the column properties, under the Default Value or Binding, I've put (newid()). I thought that this would create a new uniqueidentifier if no value is specified in the insert statement.
However, when I try to add a new row in the table data view and leave the userId blank, it does not let me add the row. It gives me an error saying that the value cannot be NULL (since it is a primary key), however I had deliberately left it NULL so that it would add a new value by calling newid(). Have I made a false assumption?
I am using SqlDataSource control that retrieves information based on a city value from another control (textbox) on the page entered by the user.
[Code]....
The query works fine when the user enters a name of a city. However, if I leave the textbox blank and enter nothing, no records are returned by the query.I need all records to be returned when user leave the textbox blank and there is no value of the city.How to do that?is there a default value can do that?
When I opened sql server configuration manager I am not able to see default databases like master etc. Does anybody know the reason? Did I miss any installation?
And get this error when I click 'Edit' and then 'Update':
Server Error in '/' Application. Could not find control 'tbDescriptiontext' in ControlParameter 'descriptiontext'.Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Could not find control 'tbDescriptiontext' in ControlParameter 'descriptiontext'.
Source Error:
[Code]....
Stack Trace:
[Code]....
[InvalidOperationException: Could not find control 'tbDescriptiontext' in ControlParameter 'descriptiontext'.] System.Web.UI.WebControls.ControlParameter.Evaluate(HttpContext context, Control control) +2961386 System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +152 System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +113 System.Web.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control) +47 System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +1204 System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +3636597 System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +1336 System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +641 System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +164 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +52 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3691
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
I'm trying to execute a simple insert statement with the GUID and timestamp populated by default from the server. I have both of their default values set as (newid()) and (getutcdate()) respectively in SQL server. However, I receive the error when I try and execute the command "Insert Error: column name or number of supplied values does not match table definition". How do I construct my sql insert so my id and timestamp columns use their default values as assigned in sql server?
I am using the query listed below which includes multiple joins, in the result of the query I need to do some value replacement valuesExample: db.ASSETS.BUILDING_ID=300 that ID does not exist in db.BUILDINGS, in that case I need to return BUILDING_ID=0, db.BUILDINGS.NAME="Unassigned"
I have a web project with more than 100 input boxes , so in every INSERT and UPDATE to sql server in front of sql statement I must put the golden N word, so it will be in UNICODE mode. Do we have some alternative of this? How can i make it in EVERY UPDATE and INSERT to sql server in data layer level- make it like u insert UNICODE (without N word) How can you get MSSQL server to accept Unicode data by default into a VARCHAR or NVARCHAR column?
I know that you can do it by placing a N in front of the string to be placed in the field but to by quite honest this seems a bit archaic in 2008 and particuarily with using SQL Server 2005. Example:
cmd = New SqlCommand(sql, ConnectionFromEnum(whichDatabase)) cmd.Connection.Open() i = cmd.ExecuteNonQuery()
so....
the question is : Am I suppose to make something with SQLCOMMAND to set- "enter evthng like it is UNICODE, with N auto"? or i must specify UNICODE by default in somewhere else? just to indicate that i already set in web.config
So global questions HOW TO MAKE INSERT AND UPDATE Unicode by default in every insert and update methods, without placing N word in front of literal string?
I have a Dynamic Data Website that I created after watching the video tutorials on this website (I'm new to programming, but not computers).I have a SQL Table named 'Adult' that has a 'DOB' column. I would like to add an asp:label to the Default.aspx that does a LINQ to SQL query to determine if it's someones birthday today and if so display their name and age.
I am using DAAB with stored procedures. I use stored procedures more then once if possible. If I add a parameter later in stored procedure, I have to supply value for this in functions where it is even not being used as well, other wise it shows an error that number of parameters are not same. if I add parameter in last of parameter list in stored procedure and set a default value for it and I may have not to provide value for this from functions where I am not using it.
I have a DataSet with multiple DataTables and I use an ObjectDataDataSource to bind my DataGrid to it. One of my tables is correctly displayed in the grid. My problem is, that the grid displays the wrong table.
My tables are related to each other - I make use of the "relation" objects in VS Studio 2010. My ObjectDataSource points to a class with a select method. The DataSet contains several DataTables (e.g. "Variables" and "Components").
[Code]....
How can I configure the DataSet to display the table "Variables" by default?
I am using forms authentication and authorization through roleManager. I have two Roles - "Customers" and "Employees". The redirection to the default page for the "Customers" role is working fine, but I get an oledb error stating that one or more parameters are not being passed when I redirect a user from the "Employees" role. The following is the code in login.aspx that handles the authentication of the user:
If myReader.Read() Then ' We have a match If myReader(1) Then ' This is true if an Employee and false otherwise If Not Roles.IsUserInRole(logInUser.UserName, "Employees") Then Roles.AddUserToRole(logInUser.UserName, "Employees") End If ElseIf Not Roles.IsUserInRole(logInUser.UserName, "Customers") Then Roles.AddUserToRole(logInUser.UserName, "Customers") End If FormsAuthentication.RedirectFromLoginPage(logInUser.UserName, logInUser.RememberMeSet) Else Response.Write("Invalid credentials") End If............................................
I have a gridview tied to a sqlDataSource. I want to filter it using FilterExpression of SqlDataSource. The controlParameter that I want to use is dropdownList SelectedItem.Value. This value is an integer. I am getting this exception: System.Data.EvaluateException:{"Cannot perform '=' operation on System.Int32 and System.String."}