ControlParameter

Jan 23, 2008

I am new to asp.net and this is the first time I have tried to use a ControlParameter from another control and I can not get it to work. FormView1 works as expected, but the controlParameter in SqlDataSource2 does not work as expected.

 A part of FormView1 and SqlDataSource1 (the source)<asp:FormView ID="FormView1" runat="server" DataKeyNames="Id"

DataSourceID="SqlDataSource1"

<ItemTemplate>

<asp:Label ID="lblCategoryName" runat="server" Text='<%# Bind("CategoryName") %>'></asp:Label>

</ItemTemplate>

</asp:FormView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

SelectCommand="SELECT [Id], [CategoryName], [ItemNumber], [Name], [Price], [SalePrice], [FullDescription], [ImageAltText], [DateSold] FROM [Products] WHERE ([Id] = @Id)">

<SelectParameters>

<asp:QueryStringParameter Name="Id" QueryStringField="Id" DefaultValue="11" />

</SelectParameters>

</asp:SqlDataSource>

 

SqlDataSource2 (where I need to use "lblCategoryName" from FormView1) <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

SelectCommand="SELECT [Id], [CategoryName], [ImageAltText], [DateSold] FROM [Products] WHERE ([CategoryName] = @CategoryName)">

<SelectParameters><asp:ControlParameter ControlID="FormView1"

DefaultValue="Earrings" Name="lblCategoryName"

PropertyName="text" Type="String" />

</SelectParameters>

</asp:SqlDataSource>

I hope someone can help me with my simple problem.

Thank you

View 1 Replies


ADVERTISEMENT

How To Add ControlParameter To SqlDataSource At Runtime?

Dec 8, 2006

Hi!
My question is exactly the subject.
My Web Form has only a GridView and a DetailsView, there is no SqlDataSource at project time, i create the SqlDataSource at runtime using code like this in the Page_Load event: (I NEED IT TO BE CREATED DYNAMICALLY)1 Dim SQLDS As SqlDataSource = New SqlDataSource()
2
3 SQLDS.ID = "CustomerDataSource"
4 SQLDS.ConnectionString = ConfigurationManager.ConnectionStrings("connectionstring").ConnectionString
5 SQLDS.SelectCommand = "select customerid,companyname,contactname,country from customers"
6 SQLDS.InsertCommand = "insert into customers(customerid,companyname,contactname,country) values(@customerid,@companyname,@contactname,@country)"
7 SQLDS.UpdateCommand = "update customers set companyname=@companyname,contactname=@contactname,country=@country where customerid=@customerid"
8 SQLDS.DeleteCommand = "delete from customers where customerid=@customerid"
9
10 SQLDS.UpdateParameters.Add(New Parameter("companyname"))
11 SQLDS.UpdateParameters.Add(New Parameter("contactname"))
12 SQLDS.UpdateParameters.Add(New Parameter("country"))
13 SQLDS.UpdateParameters.Add(New Parameter("customerid"))
14
15 Page.Controls.Add(SQLDS)
16
17 If Not Page.IsPostBack Then
18 GridView1.DataKeyNames = New String() {"customerid"}
19 GridView1.DataSourceID = SQLDS.ID
20
21 ' ... and so on
The DetailsView1 uses the same SqlDataSource to show data, but i could not find a way to synchronize the DetailsView1 with the GridView1 when a record is selected in the GridView1.How can I synchronize the DetailsView?I played with the ControlParameter but i can't find either how to add a ControlParameter in code, is there a way? Every place talking about ControlParameter shows something like this: 1 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
2 ConnectionString="<%$ ConnectionStrings:Pubs %>"
3 SelectCommand="SELECT [au_id], [au_lname], [au_fname], [state] FROM [authors] WHERE [state] = @state">
4 <SelectParameters>
5 <asp:ControlParameter Name="state" ControlID="DropDownList1" PropertyName="SelectedValue" />
6 </SelectParameters>
7 </asp:SqlDataSource>
8
 Ok. OK. But my SqlDataSource is created dynamically. Any ideas on how to solve this problem?Thanks!

View 3 Replies View Related

Set ControlParameter To Todays Date (vb)

Dec 21, 2006

Hi,I have the following sqldatasource on my page:<asp:SqlDataSource ID="rs1" runat="server" ConnectionString="<%$ ConnectionStrings:FrogConnectionString %>" SelectCommand="Proposals_DaySheet" SelectCommandType="StoredProcedure"><SelectParameters><asp:ControlParameter ControlID="Calendar1" Name="FilterDate" PropertyName="SelectedDate" Type="DateTime" DefaultValue=""/></SelectParameters></asp:SqlDataSource>How do I set the default value to today's date ?I have tried:DefaultValue="<%# DateTime.Now %>"But I get:Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.ControlParameter does not have a DataBinding event.I have also tried:DefaultValue="<%= DateTime.Now %>"But I get:System.FormatException: String was not recognized as a valid DateTime.Any ideas ?ThanksJames
 

View 4 Replies View Related

How To Specify 2 Different Selectparameters - 1 For Querystringparameter And 1 For Controlparameter

Apr 4, 2007

Hello,
I am sure there is a way to do this programmatically, but it is just not sinking in yet on how to go about this.  I have a page where I use a dropdownlist that goes into a gridview and then the selected item of the gridview into the detailsview (typical explain seen online).  So, when selecting from the dropdownlist, the gridview uses a controlparameter for the selectparameter to display the appropriate data in the gridview (and so on for the detailslist). 
My question is - I wanted to use this same page when coming in from a different page that would utilize querystring.  So, the parameter in the querystring would be for what to filter on in the gridview, so the dropdownlist (and that associated controlparameter) should be ignored.
Any suggestions on how to go about this?  I assume there is some check of some sort I should in the code (like if querystring is present, use this querystringparameter, else use the controlparameter), but I am not sure exactly what I should check for and how to set up these parameters programmatically.
 Thanks,
Jennifer

View 5 Replies View Related

SqlDataSource+ControlParameter+Textbox

Jan 15, 2008

Hi!
I have a page (a search page) with sqldatasource, gridview and set of textboxes. The sqldatasource is using stored procedure with parameters. Using the visual wizard i'm associating the parameters with apropriate textboxes controls. It all works, like a charm.
The problem arises when I input some dangerous code in any textbox , like ' or % .
I'm having exception about unenclosed strings, generally info about the possibility of sql injection.
I thought that using ControlParameters, any Parameter in fact is sqlinjection safe, but apparently it isn't.
Does anyone know the right way of achieving my goal? It's very urgent.

View 7 Replies View Related

ControlParameter And Stored Procedures

Apr 2, 2006

I'm sure I'm missing something silly.  I have 3 textboxes, a stored procedure and a gridview.  The user will put something in the 3 boxes, click submit, and see a grid with stuff (I hope).  However, the grid will only return data is I EXCLUDE the controlparameters and only use the sessionparameter.  It's like the stored proc won't even fire!
HTML:
<form id="form1" runat="server"><div>Lastname:&nbsp;<asp:textbox id="Lastname" runat="server"></asp:textbox>Hobbies:&nbsp;<asp:textbox id="Hobbies" runat="server"></asp:textbox><br />Profession:&nbsp;<asp:textbox id="Profession" runat="server"></asp:textbox><asp:button id="Button1" runat="server" text="Button" /><br /><asp:gridview skinid="DataGrid" id="GridView1" runat="server" allowpaging="True" allowsorting="True" autogeneratecolumns="False" datasourceid="SqlDataSource1"><columns><asp:boundfield datafield="Username" headertext="Username" sortexpression="Username" /><asp:boundfield datafield="Lastname" headertext="Lastname" sortexpression="Lastname" /><asp:boundfield datafield="Firstname" headertext="Firstname" sortexpression="Firstname" /></columns></asp:gridview>
<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:HOAConnectionString %>"selectcommand="spAddressBookSelect" selectcommandtype="StoredProcedure"><selectparameters><asp:sessionparameter defaultvalue="0" name="CommunityID" sessionfield="CommunityID" type="Int32" /><asp:controlparameter controlid="Lastname" name="Lastname" propertyname="Text" type="String" /><asp:controlparameter controlid="Profession" name="Profession" propertyname="Text" type="String" /><asp:controlparameter controlid="Hobbies" name="Hobbies" propertyname="Text" type="String" /></selectparameters></asp:sqldatasource>
</div>
</form>
sp signature:ALTER PROCEDURE [dbo].[spAddressBookSelect] @CommunityID int = 0,@Lastname varchar(200) = NULL,@Profession varchar(200) = NULL,@Hobbies varchar(200) = NULL

View 2 Replies View Related

How To Progtammatically Manipulate Property 'Name' Of ControlParameter?

Jun 7, 2007

Hi,
i want to programmatically manipulate the property 'Name' of a ControlParameter inside a InsertParameters tag.
This the aspx code: ------------------  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<% ......... %>"         InsertCommand="INSERT INTO .......)"            <InsertParameters>            <asp:ControlParameter Name="myname" ControlID="na" PropertyName="text" />           </InsertParameters>         </asp:SqlDataSource>
code-behind: ------------
Dim a As String         a = SqlDataSource1.InsertParameters.Item(0).ToString
but 'm stuck here
Thanks for help
Tartuffe

View 1 Replies View Related

Load ControlParameter From Page's Peoperties

Feb 25, 2008

Hi,in aspx I've SqlDataSource, in SelectParametersI can add ControlParameter and to load parametersfrom control Property, BUT I'm trying to do that:Is there way, when in <ControlParameter>to set parameter to be loaded from PAGE Property.something like that:aspx:<asp:SqlDataSource ID="_companyDS" runat="server"   ConnectionString="<%$ ConnectionStrings:tihomir_dbConnectionString %>"   SelectCommand="SELECT [companyID], [companyName], [companyInfo], [companyAddress] FROM [Companies] WHERE ([companyID] = @companyID)">   <SelectParameters>     <asp:ControlParameter ControlID="Page" PropertyName="CompanyIdent" Name="companyID" Type="Int32" DefaultValue="0" />   </SelectParameters>    </asp:SqlDataSource></asp:SqlDataSource>code behind:public partial class test : System.Web.UI.Page{   public int CompanyIdent   {      get      {         return ... some id ...;      }   }}  Best Regards,Tihomir Ivanov Best Manager Software

View 2 Replies View Related

Sending Multiple Values From A ListBox To ControlParameter

Dec 15, 2005

Any ideas on how I can send multiple values from a listbox to a stored procedure?  right now I have a ListBox Control called lbCategory, and I want to pass multiple selected items to a stored procedure.  
<asp:SqlDataSource ID="dsFS" runat="server" ConnectionString="someConnectionString" SelectCommand="usp_FS" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="lbCategory" DefaultValue="%" Name="category" PropertyName="SelectedValue" type="String" />
</SelectParameters>
</asp:SqlDataSource>

View 5 Replies View Related

Can A ControlParameter Be Used To Supply A Parameter For A Stored Procedure?

Apr 13, 2006

The code below is an attempt at using the value from a dropdownlist to feed into stored procedure outlined in the Select command. I have seen examples where the control parameter is used with a select command but nothing where the parameter has to be fed into a stored procedure.
 
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString=".."SelectCommand="procCAGetCustomerKPIs" SelectCommandType="StoredProcedure"><SelectParameters><asp:ControlParameter Name="iCustomerGroupId" ControlID="CustomerFilterList" PropertyName="SelectedValue" /></SelectParameters></asp:SqlDataSource>
 
cheers-jim.

View 2 Replies View Related

Passing Parameters To SQL Stored Procedure With SQLDataSource And ControlParameter

Mar 28, 2007

Hello,
I'm having trouble executing a Stored Procedure when I leave the input field empty on a 'search' criteria field. I presume the error is Null/Empty related.
The Stored Procedure works correctly when running in isolation. (with the parameter set to either empty or populated)
When the application is run and the input text field has one or more characters in it then the Stored Procedure works as expected as well.
 
Code:
.
.
<td style="width: 3px">
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</td>
.

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="LogId" DataSourceID="SqlDataSource1"
Width="533px">
<Columns>
<asp:BoundField DataField="LogId" HeaderText="Log Id" InsertVisible="False" ReadOnly="True"
SortExpression="LogId" />
<asp:BoundField DataField="SubmittedBy" HeaderText="Submitted By" SortExpression="SubmittedBy" />
<asp:BoundField DataField="Subject" HeaderText="Subject" SortExpression="Subject" />
<asp:TemplateField>
<ItemTemplate>
<span>
<asp:HyperLink ID="HyperLink1" runat="server">HyperLink</asp:HyperLink></span>
</ItemTemplate>
</asp:TemplateField>
 
</Columns>
<HeaderStyle BackColor="#608FC8" />
<AlternatingRowStyle BackColor="#FFFFC0" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SmallCompanyCS %>"
SelectCommand="spViewLog" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="txtName" ConvertEmptyStringToNull="true" Name="name" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
Stored Procedure:
ALTER PROCEDURE dbo.spViewLog (@name varchar(50) )
 
AS
SELECT * FROM log_Hdr WHERE (log_hdr.submittedby LIKE '%' + @name + '%')
RETURN
 
I have tried the 'convertemptystringtonull' parameter but this didn't seem to work.
 Any guidance would be much appreciated.
Thank you
Lee
 
 

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved