Ask a Question related to ASP.NET General, Design and Development.
-
S. Justin Gengo #1
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
-
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... -
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... -
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... -
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... -
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... -
Alex K #2
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
-
Lim Siew Cheng #3
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



Reply With Quote

