Solved

how to pass a textbox value to a gridview selectcommand

Posted on 2009-04-10
3
1,297 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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