Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > Visual Web Developer 2005
|
Visual Web Developer 2005 Discuss creating ASP.NET 2.0 sites with Microsoft's Visual Web Developer 2005. If your question is more specific to a piece of code than the Visual tool, see the ASP.NEt 2.0 forums instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Web Developer 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 11th, 2007, 09:07 PM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need textbox to have data upon page initialization

Here's a simple page (Cut and Paste and see what I mean) where I want my textbox (ID=TextBox1)
to have the same data as the drop down list (ID=DropDownList3) upon Page Load or Page Render or Page Init.
My problem is I CANNOT get the textbox with the data that I want
because an ASP textbox does NOT have a dataSource.

How do I set the Textbox with the value that I want?

*******************************
***** Begin of Data ***********
*******************************

drop table prod_t
create table prod_t (category varchar(10), item varchar(20), loc varchar(20))
insert into prod_t (category, item, loc) values ('CAT 1', 'CAT 1.Item 1', 'CAT 1.LOC 1')
insert into prod_t (category, item, loc) values ('CAT 1', 'CAT 1.Item 2', 'CAT 1.LOC 2')
insert into prod_t (category, item, loc) values ('CAT 1', 'CAT 1.Item 3', 'CAT 1.LOC 3')

insert into prod_t (category, item, loc) values ('CAT 2', 'CAT 2.Item 1', 'CAT 2.LOC 1')
insert into prod_t (category, item, loc) values ('CAT 2', 'CAT 2.Item 2', 'CAT 2.LOC 2')
insert into prod_t (category, item, loc) values ('CAT 2', 'CAT 2.Item 3', 'CAT 2.LOC 3')

*******************************
***** End of Data ***********
*******************************




***************************************
***** Begin of ASP.NET Code ***********
***************************************

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
            DataTextField="category" DataValueField="category" Style="z-index: 100; left: 178px;
            position: absolute; top: 104px" AutoPostBack="True">
        </asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:localsqlserver %>"
            SelectCommand="select distinct category from prod_t"></asp:SqlDataSource>
        <asp:Label ID="Label1" runat="server" Style="z-index: 101; left: 104px; position: absolute;
            top: 110px" Text="Category" Width="67px"></asp:Label>
        <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"
            DataTextField="item" DataValueField="item" Style="z-index: 102; left: 179px;
            position: absolute; top: 131px">
        </asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:localsqlserver%>"
            SelectCommand="select item from prod_t where category=@category">
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="category" PropertyName="SelectedValue" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:Label ID="label2" runat="server" Style="z-index: 103; left: 143px; position: absolute;
            top: 134px" Text="Item" Width="28px"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 104; left: 181px; position: absolute;
            top: 157px"></asp:TextBox>
        <asp:Label ID="Label3" runat="server" Style="z-index: 105; left: 43px; position: absolute;
            top: 158px" Text="Location (Textbox)" Width="130px"></asp:Label>
        <asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlDataSource3"
            DataTextField="loc" DataValueField="loc" Style="z-index: 106; left: 184px; position: absolute;
            top: 186px">
        </asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:localsqlserver%>"
            SelectCommand="select loc from prod_t where category=@category and item=@item">
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="category" PropertyName="SelectedValue" />
                <asp:ControlParameter ControlID="DropDownList2" Name="item" PropertyName="SelectedValue" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:Label ID="Label4" runat="server" Style="z-index: 108; left: 10px; position: absolute;
            top: 186px" Text="Location (DropDownList)" Width="171px"></asp:Label>

    </div>
    </form>
</body>
</html>


***************************************
***** END of ASP.NET Code ***********
***************************************



 
Old June 27th, 2007, 11:59 AM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Yeah, it won't do if for you automatically. You have to add it in the code behind, but it's easy. You just change the text property. Here's the easiest way IMO. :)

Double click the background of your design view. This opens your code behind and starts a Page_Load subroutine.

(I do everything in code behind, so it'll probably be different for you since it looks like you're not using a code behind. But I figure you know how to deal with that part. If you want to try code behind, add a new item to your website, make sure the the Place Code is Separate file box is checked and then name your page).

Intellisense will help you out, but I think you'll want...

Me.TextBox1.Text = "Hi! I fill the textbox on page load."

And you should be staring at that in the textbox when you test the page. So, you change replace the string with whatever you actually want there.

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to read data from textbox cancertropica Visual Studio 2005 4 November 12th, 2008 02:59 PM
How to get and display a data in textbox kakac ASP.NET 2.0 Basics 1 April 20th, 2007 08:12 AM
Data Validation in textbox rhd110 .NET Framework 1.x 1 March 26th, 2007 06:51 AM
textbox initialization in Formview ekwong ASP.NET 2.0 Basics 2 November 17th, 2006 08:30 PM
read data into a TEXTBOX cuwark BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 10 January 12th, 2004 04:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.