Solved

how to pass a textbox value to a gridview selectcommand

Posted on 2009-04-10
3
1,295 Views
Last Modified: 2012-05-06
I want to pass a value from a textbox to a gridview selectcommand....

See code below

<asp:TextBox CausesValidation="false" AutoPostBack="true" CssClass="textbox" ID="Date1" Width="150" runat="server" />&nbsp;
                
 
SelectCommand="SELECT [b_id], [epostID], [telefonID], [bokningsnr], [datum], [tidpunkt], [platser], [kommentar] FROM [bokningsDB] WHERE ([datum] = @Date1.Text)"

Open in new window

0
Comment
Question by:mattegol
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 500 total points
ID: 24118319
Hi,

You need to pass it as a ControlParameter rather than trying to pass it declaratively, i.e.:

SelectCommand="SELECT [b_id], [epostID], [telefonID], [bokningsnr], [datum], [tidpunkt], [platser], [kommentar] FROM [bokningsDB] WHERE ([datum] = @Date)"

And then in the datasource declare:

        <SelectParameters>
            <asp:ControlParameter ControlID="Date1" ConvertEmptyStringToNull="true" DbType="Date" Name="@Date" PropertyName="Text" />
        </SelectParameters>

Hope this helps,

/Carl.
0
 

Author Comment

by:mattegol
ID: 24122873
I get this error with that:
Must declare the scalar variable "@Date".

I have a this updatecommand to:
UpdateCommand="UPDATE bokningsDB SET epostID = @epostID, telefonID = @telefonID, bokningsnr = @bokningsnr, datum = @datum, tidpunkt = @tidpunkt, kommentar = @kommentar  WHERE b_id = @b_id">
0
 

Author Closing Comment

by:mattegol
ID: 31569017
Thank you, this helped.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question