Results 1 to 2 of 2

Thread: About data binding

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Location
    Dhaka, Bangladesh
    Posts
    102

    About data binding

    I want to bind two text boxes with the change of a combo box in web application.

    Is it possible ?

    I can bind on etext box by DataTextfield and DataValueField.

    But I am suffering when I want to bind two text box.


    Plz help me.

    ---Rajib

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: About data binding

    Correct if I'm wrong but you have a dropdownlist of value-text pairs that OnChange you want one TextBox to hold the value and the other to hold the text. If I've got the wrong end of the stick let me know!

    HTML (you might be databinding the list but I'm using hardcoded listitem for this example):
    Code:
    <asp:DropDownList id="ddlStart" runat="server" AutoPostBack="true" OnSelectedIndexChange="ddlStart_SelectedIndexChange">
    	<asp:ListItem Value="1" Text="First" />
    	<asp:ListItem Value="2" Text="second" />
    	<asp:ListItem Value="3" Text="Third" />
    	<asp:ListItem Value="4" Text="Fourth" />
    	<asp:ListItem Value="5" Text="Fifth" />
    </asp:DropDownList>
    <asp:TextBox id="txtValue" runat="server" />
    <asp:TextBox id="txtText" runat="server" />
    Code behind:
    Code:
    void ddlStart_SelectedIndexChange(object sender, EventArgs e) {
    	txtValue.Text = ddlStart.SelectedValue;
    	txtText.Text = ddlStart.Items[ddlStart.SelectedIndex];
    }
    HTH

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width