DropDownlist name customized possible ?

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Re: DropDownlist name customized possible ?

    Lim,

    If you add the drop down list to your page at design time then yes...

    The best example of this that I have is adding text boxes at design time.
    Here is the code:

    First put this code into the designer window. Paste it between the "<form>"
    tags:



    <asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True">

    <asp:ListItem Value="Please Select The Number of Text Boxes To
    Display">Please Select The Number of Text Boxes To Display</asp:ListItem>

    <asp:ListItem Value="1">1 Text Box</asp:ListItem>

    <asp:ListItem Value="2">2 Text Boxes</asp:ListItem>

    <asp:ListItem Value="3">3 Text Boxes</asp:ListItem>

    </asp:DropDownList>

    <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
    ErrorMessage="3" Font-Names="Webdings" ControlToValidate="DropDownList1"
    InitialValue="Please Select The Number of Text Boxes To
    Display"></asp:RequiredFieldValidator>

    <BR>

    <BR>

    <asp:Label id="Label1" runat="server"></asp:Label>

    <BR>

    <BR>

    <asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder>

    <BR>

    <BR>

    <asp:Button id="SubmitButton" runat="server" Text="Submit" Visible="False"
    ></asp:Button>




    Then put this code into the code behind:



    Private TextBoxCount, TextBoxLoop As Int32

    Protected WithEvents Label1 As System.Web.UI.WebControls.Label

    Protected WithEvents SubmitButton As System.Web.UI.WebControls.Button

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    If IsPostBack Then

    TextBoxCount = CType(ViewState("TextBoxCount"), Int32)

    For TextBoxLoop = 1 To TextBoxCount

    Call LoadTextBox(TextBoxLoop)

    Next



    ViewState("TextBoxCount") = TextBoxCount

    End If

    End Sub

    Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
    System.Object, ByVal e As System.EventArgs) Handles
    DropDownList1.SelectedIndexChanged

    Page.Validate()

    If Page.IsValid Then

    Label1.Text = ""



    PlaceHolder1.Controls.Clear()



    TextBoxCount = CType(DropDownList1.SelectedValue, Int32)

    For TextBoxLoop = 1 To TextBoxCount

    Call LoadTextBox(TextBoxLoop)

    Next



    SubmitButton.Visible = True

    ViewState("TextBoxCount") = TextBoxCount

    End If

    End Sub

    Private Sub LoadTextBox(ByVal Id As Int32)

    Dim TextBox As New TextBox

    TextBox.ID = "TextBox" & Id.ToString

    PlaceHolder1.Controls.Add(TextBox)



    Dim LiteralControl As New LiteralControl

    LiteralControl.Text = "<br><br>"

    PlaceHolder1.Controls.Add(LiteralControl)

    End Sub

    Private Sub SubmitButton_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles SubmitButton.Click

    Label1.Text = ""



    Dim ControlsCount, ControlsLoop As Int32

    Dim ControlType As String

    Dim TextBox As TextBox

    ControlsCount = PlaceHolder1.Controls.Count - 1

    For ControlsLoop = 0 To ControlsCount

    '---To be able to see in debugger what is returned

    ControlType =
    PlaceHolder1.Controls(ControlsLoop).GetType.ToStri ng

    If ControlType = "System.Web.UI.WebControls.TextBox" Then

    TextBox = CType(PlaceHolder1.Controls(ControlsLoop),
    TextBox)

    Label1.Text &= TextBox.Text

    If (ControlsLoop + 1) < ControlsCount Then

    Label1.Text &= " | "

    End If

    End If

    Next

    End Sub

    Notice where I assign the text boxes their Id? You could assign that from a
    database, etc.

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    [url]www.aboutfortunate.com[/url]

    "Out of chaos comes order."
    Nietzche


    "Lim siew Cheng" <siew_cheng555@yahoo.com> wrote in message
    news:3f37bbd0@news.starhub.net.sg...
    > Greetings
    >
    > Does anyone know if it is possible to define the name of a
    > dropdownlist
    > Eg.,
    >
    > <asp:DropDownList Runat="server" SelectedIndex=' <%# Convert.ToInt32
    > (DataBinder.Eval(Container.DataItem,"Priority"))-1%>' DataSource="<%#
    > GetCategories() %>" ID="<%# getName() %> ">
    > </asp:DropDownList>
    > ?
    >
    > Error : '<%# getName() %> ' is not a valid identifier.
    > Any clues ?
    >
    > Thanks for any help
    >
    > REgards
    > Lsc
    >
    >
    >

    S. Justin Gengo Guest

  2. Similar Questions and Discussions

    1. Creating customized shapes
      Hello, I'm quite new in Flex and I wanted to try to build an application using Flex. I would like to know if there is any possibility to create...
    2. customized stamps
      Hi, I work for a large firm that uses PDFs to send out to the people who review them. They use stamps to do so, but within the firm we would like...
    3. customized scroll panes
      I would like to create a scroll pane for two diffent items in a web site I doing right now. I need to scroll a timeline (which is set up as a movie...
    4. customized popup
      hi everybody we have created a pop up window customizing the aspect of the bar, etc. but the problem is that on i.e. version 6.0 it doesn't open at...
    5. Forms: customized buttons
      Hi all Anybody out there have a link to a site that offers customized button controls for access forms. I'm tired of the standard rectangular box...
  3. #2

    Default Re: DropDownlist name customized possible ?

    you put panel on aspx file and onserver side you add control to panel and
    you can give any name or value in run time
    example:
    Dim cbo As System.Web.UI.WebControls.DropDownList

    cbo = New System.Web.UI.WebControls.DropDownList()

    Panel3.Controls.Add(cbo)

    Alex



    "Lim siew Cheng" <siew_cheng555@yahoo.com> wrote in message
    news:3f37bbd0@news.starhub.net.sg...
    > Greetings
    >
    > Does anyone know if it is possible to define the name of a
    > dropdownlist
    > Eg.,
    >
    > <asp:DropDownList Runat="server" SelectedIndex=' <%# Convert.ToInt32
    > (DataBinder.Eval(Container.DataItem,"Priority"))-1%>' DataSource="<%#
    > GetCategories() %>" ID="<%# getName() %> ">
    > </asp:DropDownList>
    > ?
    >
    > Error : '<%# getName() %> ' is not a valid identifier.
    > Any clues ?
    >
    > Thanks for any help
    >
    > REgards
    > Lsc
    >
    >
    >

    Alex K Guest

  4. #3

    Default Re: DropDownlist name customized possible ?


    Hi there,

    Thanks for the swift response.

    The scenario I'm facing is rather different as what you had in mind.
    I understand it's possible for me to assign IDs IFF I had the
    dropdownlist at the codebehind.cs.

    However, it is impossible for me , since I cannot forseee how many
    records are there in the db

    Sorry to skip stating that the existing conditions :
    <asp:DropDownList Runat="server" SelectedIndex=' <%# Convert.ToInt32
    > (DataBinder.Eval(Container.DataItem,"Priority"))-1%>' DataSource="<%#
    > GetCategories() %>" ID="<%# getName() %> ">
    ^^^^^^^^^^^^^^^^^
    Are actually used in a <asp:Datagrid> </asp> block
    So in RL, there's going to be DropList_ctr1, DropList_ctrl2 etc. for
    EACH ROW of record .
    in this case, I'm allowing the user to change the field (thru the
    dropdownlist ) and I need to know what RECORD the droplist_1 is for
    ..........

    ID="<% # DataBinder.Eval(Container.DataItem,"TitleID") %>"
    Does not work....


    Apparently, this has been causing enough distress so someone has done this
    See :
    [url]http://www.datagridgirl.com/rowselector.aspx[/url]

    Alas, I saw the code in action and shrudder to think I have to CODE THAT
    much IN ORDER to assign & know the ID for each row! (I'm not lazy, I'm
    just horrified to know the amount of work that needs to be done )
    I'm still way too templated to literate thru a collection of
    ValueObjects :)



    Regards
    (The still clueless) LSc













    S. Justin Gengo wrote:
    > Lim,
    >
    > If you add the drop down list to your page at design time then yes...
    >
    > The best example of this that I have is adding text boxes at design time.
    > Here is the code:
    >
    > First put this code into the designer window. Paste it between the "<form>"
    > tags:
    >
    >
    >
    > <asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True">
    >
    > <asp:ListItem Value="Please Select The Number of Text Boxes To
    > Display">Please Select The Number of Text Boxes To Display</asp:ListItem>
    >
    > <asp:ListItem Value="1">1 Text Box</asp:ListItem>
    >
    > <asp:ListItem Value="2">2 Text Boxes</asp:ListItem>
    >
    > <asp:ListItem Value="3">3 Text Boxes</asp:ListItem>
    >
    > </asp:DropDownList>
    >
    > <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
    > ErrorMessage="3" Font-Names="Webdings" ControlToValidate="DropDownList1"
    > InitialValue="Please Select The Number of Text Boxes To
    > Display"></asp:RequiredFieldValidator>
    >
    > <BR>
    >
    > <BR>
    >
    > <asp:Label id="Label1" runat="server"></asp:Label>
    >
    > <BR>
    >
    > <BR>
    >
    > <asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder>
    >
    > <BR>
    >
    > <BR>
    >
    > <asp:Button id="SubmitButton" runat="server" Text="Submit" Visible="False"
    >
    >></asp:Button>
    >
    >
    >
    >
    >
    >
    > Then put this code into the code behind:
    >
    >
    >
    > Private TextBoxCount, TextBoxLoop As Int32
    >
    > Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    >
    > Protected WithEvents SubmitButton As System.Web.UI.WebControls.Button
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    >
    > If IsPostBack Then
    >
    > TextBoxCount = CType(ViewState("TextBoxCount"), Int32)
    >
    > For TextBoxLoop = 1 To TextBoxCount
    >
    > Call LoadTextBox(TextBoxLoop)
    >
    > Next
    >
    >
    >
    > ViewState("TextBoxCount") = TextBoxCount
    >
    > End If
    >
    > End Sub
    >
    > Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
    > System.Object, ByVal e As System.EventArgs) Handles
    > DropDownList1.SelectedIndexChanged
    >
    > Page.Validate()
    >
    > If Page.IsValid Then
    >
    > Label1.Text = ""
    >
    >
    >
    > PlaceHolder1.Controls.Clear()
    >
    >
    >
    > TextBoxCount = CType(DropDownList1.SelectedValue, Int32)
    >
    > For TextBoxLoop = 1 To TextBoxCount
    >
    > Call LoadTextBox(TextBoxLoop)
    >
    > Next
    >
    >
    >
    > SubmitButton.Visible = True
    >
    > ViewState("TextBoxCount") = TextBoxCount
    >
    > End If
    >
    > End Sub
    >
    > Private Sub LoadTextBox(ByVal Id As Int32)
    >
    > Dim TextBox As New TextBox
    >
    > TextBox.ID = "TextBox" & Id.ToString
    >
    > PlaceHolder1.Controls.Add(TextBox)
    >
    >
    >
    > Dim LiteralControl As New LiteralControl
    >
    > LiteralControl.Text = "<br><br>"
    >
    > PlaceHolder1.Controls.Add(LiteralControl)
    >
    > End Sub
    >
    > Private Sub SubmitButton_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles SubmitButton.Click
    >
    > Label1.Text = ""
    >
    >
    >
    > Dim ControlsCount, ControlsLoop As Int32
    >
    > Dim ControlType As String
    >
    > Dim TextBox As TextBox
    >
    > ControlsCount = PlaceHolder1.Controls.Count - 1
    >
    > For ControlsLoop = 0 To ControlsCount
    >
    > '---To be able to see in debugger what is returned
    >
    > ControlType =
    > PlaceHolder1.Controls(ControlsLoop).GetType.ToStri ng
    >
    > If ControlType = "System.Web.UI.WebControls.TextBox" Then
    >
    > TextBox = CType(PlaceHolder1.Controls(ControlsLoop),
    > TextBox)
    >
    > Label1.Text &= TextBox.Text
    >
    > If (ControlsLoop + 1) < ControlsCount Then
    >
    > Label1.Text &= " | "
    >
    > End If
    >
    > End If
    >
    > Next
    >
    > End Sub
    >
    > Notice where I assign the text boxes their Id? You could assign that from a
    > database, etc.
    >
    > Sincerely,
    >
    Lim Siew Cheng Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139