Solved

how to pass a textbox value to a gridview selectcommand

Posted on 2009-04-10
3
1,302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

729 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