Setting the Parameter Value to the Property Value of a Web Control

I want to filter my DetailsView with a declarative parameter. In my case, I am setting the SqlDataSource's parameter values based on the value of 2 TextBox controls on the page.

I have a SP that does a SELECT based on 1 of the parameters passed in (either an ID or phone number).

Param Name          Value
MemberID          TextBox1.Text
Phone               TextBox2.Text

I want to assign a default value of 'null' for both. BUT null doesn't work for MemberID because it's of type int. I got the error:


Error converting data type nvarchar to int. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Error converting data type nvarchar to int.



Is there a way to set the default value of MemberID to null? In my SP, I have both input parameters initialized to null, but it seems like I have to do it on the page too in order for it to work.

Please advise!

11/26/2008 3:36:54 PM 72751 articles. 3 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 47

Can anyone help??


11/27/2008 1:17:04 AM

Hi sas0riza,

You can set ConvertEmptyStringToNull="true" or set DefaultValue in SelectParameters.


Qin Dian Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
12/1/2008 3:22:23 AM

I did try that for one of the textboxes, but because it's a parameter for an ID field, I got an error about can't convert nchar to int...

12/1/2008 2:24:58 PM

Hi sas0riza,

Usually ID field is some kind of primary key or identity of an object, so I strongly suggest you to use Validator control or any code checking not to make it null. You can check it in Searching Button Click event to see if it is null or not. If it is null, not searching. Or you can set a number to DefaultValue in parameter.


Qin Dian Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
12/2/2008 2:38:39 AM

Similar Artilces:

Adding a property to a user control, setting property at design time, then using value in control markup
 I have made a custom control that outputs a bunch of html. I have added a property through the code behind like this:  private string sectionID; public string SectionID { get { return sectionID; } set { sectionID = value; } } This property is now showing up in Intellisense, and I can specify the value when adding the control to my page like this: <ccl:MyControl runat="server" SectionID="2" /> I now want to use this value in the markup that the control outputs. I thi...

Control.Value and Control.SelectedItem.Value
Can someone explain to me the difference between say, Dropdownlist.SelectedItem.Value and Dropdownlist.SelectedValue?? Just curious, Thanks!Tim These are going to return the same thing. dropdownlist.selectedvalue is a shortcut to get the currently selected value in the dropdown. If that is all you want then you can just use that. If you want to access the currently selected item you can use dropdownlist.selecteditem and that return the item and you can then access any of the item's properties, including in this case the value property. If this post answered your question please r...

Passing values from a parent web control to child web control
I have a parent control which called CONTROL1 and a child control witch called CONTROL2 I would link to pass a value from the parent control to the child control. In the parent control(CONTROL1) I have the following Event Handler . private void btn_Handler(object sender, EventArgs e) { …      if (Page.IsPostBack) {              // Send the officer names to the child controls.             if(m_nameList.SelectedItem.Text != "")     ...

when loading a previously created record on to form, some controls are missing values(controls are depended on values selected in other controls)
Hello - I have created a page for Editing records.  this page will open up a chosen record and allow user to edit the data.On the form, I have 3 drop down lists.   The second dropdown list should fill values depending on value chosen in first dropdown list.  The third dropdown list should show/fill values depending on value chosen in second dropdown list.So taking this into count, i have several records with various data.  When I open-up/load a record in Edit form, only the first dropdown list has a value selected that was the pre-existing va...

new to .net, need help setting db values from checkbox's then retrieving value to a label control
Hi, Being new to i know this possible i just can't quite get it right!  I need a page with 5 checkbox's that when submitted sets the bit values in DB fields to checked. Then i need another page that retrieves the records of the checkboxes, but instead of having the db pre-set checkboxes on the second page i want it to turn on label web controls depending on if the check box is set.. I hope that makes sense?!! Can anyone point me in the right direction or to a suitable tutorial? Thanks in advance Ben Excellent article here.

Update parameters and Control parameters: how do you set a default value
I have a Db update that I want to set the lastupdate column to be the date & time of right now.  Can anyone tell me who I can do that in a ControlParameter using the Default value?  Or is there another way it is done when adding parameters to the UpdateParameters tag?  Thanks for the help!!   Don't use a parameter.  Use GetDate() in your SQL (or Now() if using Access)Regards Mike [MVP - ASP/ASP.NET]My site...

Pass 1 control value to another control value
I have this form, is the detailsview, and in edit mode, I have a link that you click to open up a small dhtml window (not a new window but more like a layer so everything is on the same page).  When I select an item from the dhtml window, it puts the value into a textbox.  I then have a button I click and I want to pass that value from that textbox to the textbox in the detailsview.  When I click the button, the value is not passed. Here is the code I use for getting the value from the dhtml window and assigning it to the detailsview textbox: If e.CommandName = "pi...

Setting parent control values from user control
Hi there, I'm having a little trouble with user controls...Basically I have an aspx page with a number of components on it. On the page load, I want to call a function in an external (reusable) class or control to set the text of all the buttons on the aspx page.I've tried to use a user control to do this using the following:The user control has one function in it, in the C# behind --public void setText(){ for(int i = 0; i < this.Controls.Count; i++){      String type = this.Controls[ i ].GetType().ToString();     &nbs...

The value set to controls at client side donot persist for each page load, else it is again set to the default value...??
 I am trying to set date to the textbox field using javascript (Client side), the function is as follows. function From_calendarPicker(){                                var    sDPath = "../Calender.aspx";                 var    oWin = window.showModalDialog(sDPath, null, "dialogWidth:300px;dialogHeight:250px;help:0;status:0;scroll:0;center:1");  &nbs...

setting non server control values: input type="text" how to set value programmatically?
<form id="someForm" runat="server" enableviewstate="true">  <input id="manualtextbox" type="text" value="abc" name="manualtextbox" /></form> I have access to user supplied value via: string userEnteredThisInForm = Request.Params["manualtextbox"] but, how can I set the value when sending form back to browser? If it's not runat="server" then you'll have to emit javascript to set the value: document.getElementById('manualtextbox').value = '<desired value>'; add runat="sever" to the control  <input id="manualtextbox" type="text" value="abc" name="m...

Use property value in custom control child control
Hello, I am creating a custom control and I have the following property:   <Bindable(True), Category("Appearance"), DefaultValue(""), Localizable(True)> Property Text() As String     Get       Dim s As String = CStr(ViewState("Text"))       If s Is Nothing Then         Return String.Empty       Else         Return s       End If     End Get     Set(ByVal Value As String)       ViewState("Tex...

how to accessing values and set values for a controls that is inside a datagrid
hi this is chandra mohan working as software engineer . here i am having problem with accessing valuse and setting values for controls inside a datagrid. actually i am having datagrid and in this grid i am having item templates of one dropdwon list and text box. i having one Reset link buttion out side the grid(that is in the form) by clicking this Reset Link buttion it should invokes the javascript function and in that function it should set all textboxes of datagrid to  .. txtActionVal.readOnly = true;   txtActionVal.Value ="";and dropdownlist to  dropdownlist...

Web custom control does not maintain values of child controls
Hello everybody A few days now, I am struggling with a custom web control I am creating, which consists of 3 drop down lists (country/city/hotel).Procedure is simple: On country change, I have to fill the cities with autopostback, and on city change I have to fill hotels again with auto postback. I tried many many methods and I am confused... The best I managed to make is keep the state of countries, and render it with the selected country, selected while filling cities with apporpriate data, however I cannot manage to do the same with the cities/hotels since sities does not keep selected va...

Set TextBox text value to value from DataList Control
I'm sure this is a totally sad question to ask, but... I am using a DataList View to display data. I have a separate form within a LoginView that I would like to use to update a few main fields. I want to set the Text property of the TextBox in my custom edit form to the value of the corresponding field in the DataList. Is this possible? I think i get your question --> you want the text from a  textbox from the datalist to be input into a textbox within your form? try:TextBox tb = DataList1.FindControl("TextBoxIDToFind"); TextBoxOnForm.Text = tb.Text;David Ki...

Web resources about - Setting the Parameter Value to the Property Value of a Web Control -

Parameter - Wikipedia, the free encyclopedia
A parameter (from the Ancient Greek παρά , "para", meaning "beside, subsidiary" and μέτρον , "metron", meaning "measure"), in its common meaning, ...

fb_source Parameter - Facebook-Entwickler
This document lists the complete list of values for the fb_source parameter that is returned with th...

Google / Firefox Parameter - Flickr - Photo Sharing!
HS what?

Cat 8: TIA performance standards committee chairman previews parameters of forthcoming twisted-pair cable ...
Category 8, the next-generation twisted-pair cabling specification, is still in development, but the outlook looks quite positive that it will ...

Philippine president asks for 'parameters' of Mayon Volcano tours
Philippine president asks for 'parameters' of Mayon Volcano tours People's Daily Online ... 26, 27, 28, 29, 30, 31. Jan, Feb, Mar, Apr, May, ...

Alternatives to boolean parameters
... ) { PrintLine ( item . Name ); if ( printDetails ) { PrintLine ( item . Description ); } } } Aha! Now can see that the boolean parameter ...

Exporting Error (Error in Parameter...: Apple Support Communities
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability ...

Apple tech monitors device aging, adjusts operating parameters to ensure optimal performance
... describing a method of monitoring the aging of a device's electronics, comparing the data with a global average and modifying operating parameters ...

Is it poor programming practice to pass parameters as objects?
... a free, community-powered network of 100+ Q&A sites . Risser asked: So, we've got a guy who likes to write methods that take Objects as parameters, ...

Parameter Short Film Competition sponsored by Grolsch
Grolsch presents Parameter The A.V. Club Short Film Competition Please Enter Your Date of Birth Ineligible entry Enter For people over the age ...

Resources last updated: 1/22/2016 11:15:26 AM