Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically position a DropDownList in ASP.NET

Status
Not open for further replies.

chuair

Programmer
Apr 9, 2001
20
SG
Hi,

Can I programmatically reposition my DropDownList in ASP.NET using C#? I am designing a form where on load it will only show a DropDownList with, let's say, countries for the user to select. After the user selected a country, a table will appear and thus I wants to push down the DropDownList so that the user can select another country and another table will be displayed without the first table wiped out.

Any idea?

Thanks.




Chuair
 
I think that normally the dropdownlist would be on top of the screen since the table can fill the screen/window and the user would think that it is no longer available.
Anyway you can change the page layout to flowlayout or position some controls in a panel.

Not sure how to change the top of a control but I think this should work:
.Style("top")="88px"



Greetings, Harm Meijer
 
Hi,

Thanks for the prompt answer. Tried but still it won't move down.

:(
 
Because the elements height change dynamically I would advice using flow layout for the form.
To change the position of an item programmatically you can do the following:

in the aspx page:
<%@ Page Language=&quot;vb&quot; AutoEventWireup=&quot;false&quot; Codebehind=&quot;default.aspx.vb&quot; Inherits=&quot;testnet._default&quot;%>
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<HEAD>
<title>default</title>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft Visual Studio.NET 7.0&quot;>
<meta name=&quot;CODE_LANGUAGE&quot; content=&quot;Visual Basic 7.0&quot;>
<meta name=vs_defaultClientScript content=&quot;JavaScript&quot;>
<meta name=vs_targetSchema content=&quot; </HEAD>
<body MS_POSITIONING=&quot;GridLayout&quot;>

<form id=&quot;Form1&quot; method=&quot;post&quot; runat=&quot;server&quot;>
<asp:Button id=Button1 style=&quot;Z-INDEX: 101; LEFT: 250px; POSITION: absolute; TOP: 267px&quot; runat=&quot;server&quot; Text=&quot;Button&quot; Width=&quot;283px&quot; Height=&quot;87px&quot;></asp:Button>
<asp:Label id=Label1 style=&quot;Z-INDEX: 102; LEFT: 239px; POSITION: absolute; TOP: 154px&quot; runat=&quot;server&quot; Width=&quot;302px&quot; Height=&quot;111px&quot;>Label</asp:Label>

</form>

</body>
</HTML>

in the code behind:
Public Class _default
Inherits System.Web.UI.Page
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Dim str1 = &quot;&quot;
Dim str2 = &quot;kljdsflkfjlsadkjf<br>kljdsflkfjlsadkjf<br>kljdsflkfjlsadkjf<br>kljdsflkfjlsadkjf<br>kljdsflkfjlsadkjf<br>kljdsflkfjlsadkjf<br>kljdsflkfjlsadkjf<br>kljdsflkfjlsadkjf<br>kljdsflkfjlsadkjf<br>kljdsflkfjlsadkjf<br>&quot;

#Region &quot; Web Form Designer Generated Code &quot;

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Label1.Text = Me.str1 Then
Label1.Text = str2
Button1.Attributes(&quot;style&quot;) = &quot;Z-INDEX: 101; LEFT: 250px; POSITION: absolute; TOP: 1000px&quot;
Else
Label1.Text = str1
End If
End Sub
End Class




Greetings, Harm Meijer
 
It works! It works! It works! It works! Thanks a lot. I am so happy. But erm....... How do I get the Top value? I wants to programmatically add the Top value so that it will always move down everytime the user click the add button and more tables shows up on the top and the button is always at the bottom. Can I actually do that? I can right?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top