Solved

TextBox Data Binding source c# aspx

Posted on 2006-11-10
13
1,610 Views
Last Modified: 2012-06-21
Hi

    I need to bind a text box from a database table field,  When I drag the TextBox I was supprise that there is no binding proprety.  What can I do? and how?

Thanks
0
Comment
Question by:SylvainBissonnette
[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
  • 6
  • 4
  • 3
13 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 17915780
There is a binding property.
You can either specify the databinding in the databindings perperties in the properties window of the text box or you can add it programmatically:

e.g :

this.textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet1, "Table1.Column1"));
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17915800
or bind direct to the datatable :

this.textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataTable1, "Column1"));
0
 

Author Comment

by:SylvainBissonnette
ID: 17916326
Hi thanks for your reply,

     After re-verifying there is no binding proprety for the textbox in C# aspx Visual Studio 2005,
Here is the proprety

(Expressions)
(ID)
AccessKey
AutoCompleteType
AutoPostBack
BackColor
BorderColor
BorderStyle
BorderWidth
CausesValidation
Colomns
CssClass
Enavled
EnableTheming
EnableViewState
Font
ForColor
Height
MaxLength
ReadOnly
Rows
SkinID
TabIndex
Text
ToolTip
ValidationGroup
Visible
Width
Wrap

and there is no textBox1.DataBindings  Only TextBox1.DataBind()

Thanks again
Sylvain Bissonnette
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 6

Expert Comment

by:VovinE
ID: 17916621
There is no DataBinding for TextBox control in ASP.NET, but you may define your own databinding for the whole page.
The glitch is that you would be required to call Page.DataBind() method to bind your data.

In the aspx code you can use <%# %> tags, to indicate databinding. It can occur anywhere on the aspx in the raw page content, in an attribute or somewhere else.
But just mind that such databinding is one direction only.

hope it helps.
0
 

Author Comment

by:SylvainBissonnette
ID: 17916802
I had on my web form 5 dropdown list that I had bind via the proprety window, how could I use my SQLDataSource and by my source code get the result of the select query I had configure via the wizzard? It should have a simple way to bind a simple textbox via a datasource?

Sylvain
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17916841
Oh, sorry.
I did not realise you were using a asp.net textbox, I thought it was a winforms textbox.
0
 

Author Comment

by:SylvainBissonnette
ID: 17927586
Hi,

    Ater 20 hours of work I found that this code work but is there a way to make it directly in the aspx file and nothing in the cs file?

Thanks

    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!IsPostBack)
        {
            DataView dw = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
            Value = dw[0]["DeviceName"].ToString();
            DataBind();
        }
    }

<body>
    <form id="form1" runat="server">
        &nbsp;<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
            ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>" SelectCommand="SELECT * FROM Device WHERE (DeviceID = 350)">
        </asp:SqlDataSource>

        <asp:Label ID="Label1" runat="server" Text='<%# Value %>'></asp:Label>

    </form>
</body>
0
 
LVL 6

Accepted Solution

by:
VovinE earned 125 total points
ID: 17928286
<body>
    <form id="form1" runat="server">
        &nbsp;<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
            ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>" SelectCommand="SELECT * FROM Device WHERE (DeviceID = 350)">
        </asp:SqlDataSource>

        <asp:Label ID="Label1" runat="server" Text='<%# ((DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty))[0]["DeviceName"].ToString() %>'></asp:Label>

    </form>
</body>

plus only DataBind call is needed on the codebehind class (in cs file).
0
 
LVL 6

Expert Comment

by:VovinE
ID: 17928299
If don't want anything in the .cs file you may put add <script runat="server"> tag to your aspx file.

<script runat="server">
            private void Page_Load(object sender, System.EventArgs e)
            {
            if (!Page.IsPostBack)
                DataBind();
            }
</script>

to use it make sure AutoWireEvents is set to true.


0
 

Author Comment

by:SylvainBissonnette
ID: 17931033
Hi VovinE,

   You are right at 99% it give me a error:
The type or namespace name 'DataView' could not be found (are you missing a using directive or an assembly reference?)      C:\Zip\test\Default.aspx      14

Sylvain      
0
 

Author Comment

by:SylvainBissonnette
ID: 17931256
Hi, VovinE,

   I just found the 1% missing I had to put in the top of my aspx file
<%@ Import Namespace="System.Data" %>

Thanks a lot for your knowleage
Sylvain


0
 

Author Comment

by:SylvainBissonnette
ID: 17931332
Me again,

   Where I have to put the  AutoWireEvents?

Sylvain
0
 
LVL 6

Expert Comment

by:VovinE
ID: 17933075
Sorry, I meant AutoEventWireup at the page directive:

<%@ Page Language="c#" AutoEventWireup="true" Codebehind="default.aspx.cs" Inherits="default"%>

Such directive should be on every aspx page :)
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Suggested Courses

739 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