Showing posts with label listbox. Show all posts
Showing posts with label listbox. Show all posts

Saturday, March 31, 2012

set an event in a ListBox in runtime

I want to create a ListBox in runtime

dim objCoun as new listbox
objCoun.id = "lbxCountries"
objCoun.Rows = "1"
objCoun.DataTextField = "Country_Name"
objCoun.DataValueField = "Country_Id"

But when I try to set the event

objCoun.OnSelectedIndexChanged="tro"

This is the error message:

Compiler Error Message: BC30390: 'System.Web.UI.WebControls.ListControl.Protected Overridable Sub OnSelectedIndexChanged(e As System.EventArgs)' is not accessible in this context because it is 'Protected'.

Source Error:

Line 44: objCoun.DataTextField = "Country_Name"
Line 45: objCoun.DataValueField = "Country_Id"
Line 46: objCoun.OnSelectedIndexChanged = "tro"
Line 47: objCoun.DataSource=dbread
Line 48: objCoun.DataBind()

How can I set the event in runtime?

Thanks for your helpTry:


AddHandler objCoun.SelectedIndexChanged, AddressOf tro

...assuming tro is the name of your event handler with the appropriate signature:

Private Sub tro(ByVal sender As System.Object, ByVal e As System.EventArgs)

"tro" is the subroutine name. That means when the objCoun changes its index then the action is sent to "tro"

Monday, March 26, 2012

Set display order of ListBox control

Hi
I have a ListBox control in my ASP.NET page. After I binding data to this
control, I would like to be able to change this display order of items in
this control. Just like change layout function of my.yahoo.com.
I tried client side approach, yes I can change display order by JavaScript,
but after clicking one of the button the display order will reverse back to
its original status. Because after PostBack, the page will try to render
this control by viewstate again.

I tried server side approach, but looks there is no way to switch two
ListItems programmatically.

Is there anybody who has some good idea?

Thanks!

--

WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours HardyI already solved this problem.

"Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
news:upQn0K$KEHA.628@.TK2MSFTNGP11.phx.gbl...
> Hi
> I have a ListBox control in my ASP.NET page. After I binding data to this
> control, I would like to be able to change this display order of items in
> this control. Just like change layout function of my.yahoo.com.
> I tried client side approach, yes I can change display order by
JavaScript,
> but after clicking one of the button the display order will reverse back
to
> its original status. Because after PostBack, the page will try to render
> this control by viewstate again.
> I tried server side approach, but looks there is no way to switch two
> ListItems programmatically.
>
> Is there anybody who has some good idea?
> Thanks!
> --
>
> WWW: http://hardywang.1accesshost.com
> ICQ: 3359839
> yours Hardy
How?
--
Joe Fallon

"Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
news:O7ZTxp$KEHA.2244@.tk2msftngp13.phx.gbl...
> I already solved this problem.
>
> "Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
> news:upQn0K$KEHA.628@.TK2MSFTNGP11.phx.gbl...
> > Hi
> > I have a ListBox control in my ASP.NET page. After I binding data to
this
> > control, I would like to be able to change this display order of items
in
> > this control. Just like change layout function of my.yahoo.com.
> > I tried client side approach, yes I can change display order by
> JavaScript,
> > but after clicking one of the button the display order will reverse back
> to
> > its original status. Because after PostBack, the page will try to render
> > this control by viewstate again.
> > I tried server side approach, but looks there is no way to switch two
> > ListItems programmatically.
> > Is there anybody who has some good idea?
> > Thanks!
> > --
> > WWW: http://hardywang.1accesshost.com
> > ICQ: 3359839
> > yours Hardy
Dump content of listbox to array, sort array in memory, then clear this
listbox and add listitem from array one by one.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"Joe Fallon" <jfallon1@.nospamtwcny.rr.com> wrote in message
news:%23nd3uPALEHA.3052@.TK2MSFTNGP12.phx.gbl...
> How?
> --
> Joe Fallon
>
> "Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
> news:O7ZTxp$KEHA.2244@.tk2msftngp13.phx.gbl...
> > I already solved this problem.
> > "Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
> > news:upQn0K$KEHA.628@.TK2MSFTNGP11.phx.gbl...
> > > Hi
> > > I have a ListBox control in my ASP.NET page. After I binding data to
> this
> > > control, I would like to be able to change this display order of items
> in
> > > this control. Just like change layout function of my.yahoo.com.
> > > I tried client side approach, yes I can change display order by
> > JavaScript,
> > > but after clicking one of the button the display order will reverse
back
> > to
> > > its original status. Because after PostBack, the page will try to
render
> > > this control by viewstate again.
> > > > I tried server side approach, but looks there is no way to switch two
> > > ListItems programmatically.
> > > > > Is there anybody who has some good idea?
> > > > Thanks!
> > > > --
> > > > > > WWW: http://hardywang.1accesshost.com
> > > ICQ: 3359839
> > > yours Hardy
> >
Yep.
That is what my listbox sort routine does.
Just wondering if you came up with something different.
--
Joe Fallon

"Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
news:uVlWuSFLEHA.3808@.TK2MSFTNGP12.phx.gbl...
> Dump content of listbox to array, sort array in memory, then clear this
> listbox and add listitem from array one by one.
> --
> WWW: http://hardywang.1accesshost.com
> ICQ: 3359839
> yours Hardy
> "Joe Fallon" <jfallon1@.nospamtwcny.rr.com> wrote in message
> news:%23nd3uPALEHA.3052@.TK2MSFTNGP12.phx.gbl...
> > How?
> > --
> > Joe Fallon
> > "Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
> > news:O7ZTxp$KEHA.2244@.tk2msftngp13.phx.gbl...
> > > I already solved this problem.
> > > > > "Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
> > > news:upQn0K$KEHA.628@.TK2MSFTNGP11.phx.gbl...
> > > > Hi
> > > > I have a ListBox control in my ASP.NET page. After I binding data to
> > this
> > > > control, I would like to be able to change this display order of
items
> > in
> > > > this control. Just like change layout function of my.yahoo.com.
> > > > I tried client side approach, yes I can change display order by
> > > JavaScript,
> > > > but after clicking one of the button the display order will reverse
> back
> > > to
> > > > its original status. Because after PostBack, the page will try to
> render
> > > > this control by viewstate again.
> > > > > > I tried server side approach, but looks there is no way to switch
two
> > > > ListItems programmatically.
> > > > > > > > Is there anybody who has some good idea?
> > > > > > Thanks!
> > > > > > --
> > > > > > > > > > WWW: http://hardywang.1accesshost.com
> > > > ICQ: 3359839
> > > > yours Hardy
> > > > > >

Saturday, March 24, 2012

set focus to textbox after click event- tried everything please please help!

Hello-
I have a form which has a listbox, a textbox and a submit button. The
user types a phone number into the textbox, clicks button, text gets
added to the listbox. After this process I need the focus to be back
in the textbox. Sounds easy hu?
Here's my code-

Private Sub cmdAddLine_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAddLine.Click

lstLines.Items.Add(PhoneFormat(txtAddLine.Text))
txtAddLine.Text = ""
setFocus(txtAddLine)

End Sub

Public Sub setFocus(ByVal ctrl As System.Web.UI.Control)

Dim strS As String
strS = "<SCRIPT language='javascript'>document.getElementById('" +
ctrl.ID + "').focus();</SCRIPT>"
RegisterStartupScript("focus", strS)

End Sub

This will not place the focus in the textbox. What am I missing?

Again, PLEASE help. Thanks much!On 7 Jul 2004 10:42:20 -0700, JC <ujjc001@.charter.net> wrote:

> Hello-
> I have a form which has a listbox, a textbox and a submit button. The
> user types a phone number into the textbox, clicks button, text gets
> added to the listbox. After this process I need the focus to be back
> in the textbox. Sounds easy hu?
> Here's my code-
> Private Sub cmdAddLine_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles cmdAddLine.Click
> lstLines.Items.Add(PhoneFormat(txtAddLine.Text))
> txtAddLine.Text = ""
> setFocus(txtAddLine)
> End Sub
> Public Sub setFocus(ByVal ctrl As System.Web.UI.Control)
> Dim strS As String
> strS = "<SCRIPT language='javascript'>document.getElementById('" +
> ctrl.ID + "').focus();</SCRIPT>"
> RegisterStartupScript("focus", strS)
> End Sub
> This will not place the focus in the textbox. What am I missing?
> Again, PLEASE help. Thanks much!

Do you get a JS error? I assume you are; your control will get a unique
client ID that .NET creates on the actual HTML, so you can't just look for
ctrl.ID. Try ctrl.ClientID

http://msdn.microsoft.com/library/e...rmscontrols.asp

--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
gah, dang sig...ignore, just testing/updating my sig correctly..

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
On 7 Jul 2004 10:42:20 -0700, ujjc001@.charter.net (JC) wrote:

>Hello-
>I have a form which has a listbox, a textbox and a submit button. The
>user types a phone number into the textbox, clicks button, text gets
>added to the listbox. After this process I need the focus to be back
>in the textbox. Sounds easy hu?
>Here's my code-
>Private Sub cmdAddLine_Click(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles cmdAddLine.Click
>lstLines.Items.Add(PhoneFormat(txtAddLine.Text))
>txtAddLine.Text = ""
>setFocus(txtAddLine)
>End Sub
>Public Sub setFocus(ByVal ctrl As System.Web.UI.Control)
>Dim strS As String
>strS = "<SCRIPT language='javascript'>document.getElementById('" +
>ctrl.ID + "').focus();</SCRIPT>"
>RegisterStartupScript("focus", strS)
>End Sub
>This will not place the focus in the textbox. What am I missing?
>Again, PLEASE help. Thanks much!

Put a blank label at the bottom of the form and set its text property
in the codebehind instead of using the registerstartupscript.

-Adam
:o) You're all wrong. I took and made a clean application and it
worked, so I knew it wasn't the code there. I went back to my app,
(made a copy) and proceded to strip everything out until it worked.
Well, after everything was gone it still didn't work. There was only
one remaining thing, smartnavigaion = true.
That fixed the focus problem by turning it off, however it introduced a
whole new set of problems.
Having a database application, the users need to not use the back
button. I've got all the standard code for this but it's still not as
clean as smartnav.
Is there ANY way to overcome smartnav's focus problem?
MICROSOFT??
I didn't think so.
Anyhow, I've solved one problem only to intoduce many more. I may have
more ?'s soon, some really good ones I've been working on. Thanks for
the help so far.
Jeff

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

set focus to textbox after click event- tried everything please please help!

Hello-
I have a form which has a listbox, a textbox and a submit button. The
user types a phone number into the textbox, clicks button, text gets
added to the listbox. After this process I need the focus to be back
in the textbox. Sounds easy hu?
Here's my code-
Private Sub cmdAddLine_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAddLine.Click
lstLines.Items.Add(PhoneFormat(txtAddLine.Text))
txtAddLine.Text = ""
setFocus(txtAddLine)
End Sub
Public Sub setFocus(ByVal ctrl As System.Web.UI.Control)
Dim strS As String
strS = "<SCRIPT language='javascript'>document.getElementById('" +
ctrl.ID + "').focus();</SCRIPT>"
RegisterStartupScript("focus", strS)
End Sub
This will not place the focus in the textbox. What am I missing?
Again, PLEASE help. Thanks much!On 7 Jul 2004 10:42:20 -0700, JC <ujjc001@.charter.net> wrote:

> Hello-
> I have a form which has a listbox, a textbox and a submit button. The
> user types a phone number into the textbox, clicks button, text gets
> added to the listbox. After this process I need the focus to be back
> in the textbox. Sounds easy hu?
> Here's my code-
> Private Sub cmdAddLine_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles cmdAddLine.Click
> lstLines.Items.Add(PhoneFormat(txtAddLine.Text))
> txtAddLine.Text = ""
> setFocus(txtAddLine)
> End Sub
> Public Sub setFocus(ByVal ctrl As System.Web.UI.Control)
> Dim strS As String
> strS = "<SCRIPT language='javascript'>document.getElementById('" +
> ctrl.ID + "').focus();</SCRIPT>"
> RegisterStartupScript("focus", strS)
> End Sub
> This will not place the focus in the textbox. What am I missing?
> Again, PLEASE help. Thanks much!
Do you get a JS error? I assume you are; your control will get a unique
client ID that .NET creates on the actual HTML, so you can't just look for
ctrl.ID. Try ctrl.ClientID
http://msdn.microsoft.com/library/e...br />
rols.asp
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
gah, dang sig...ignore, just testing/updating my sig correctly..
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
On 7 Jul 2004 10:42:20 -0700, ujjc001@.charter.net (JC) wrote:

>Hello-
>I have a form which has a listbox, a textbox and a submit button. The
>user types a phone number into the textbox, clicks button, text gets
>added to the listbox. After this process I need the focus to be back
>in the textbox. Sounds easy hu?
>Here's my code-
>Private Sub cmdAddLine_Click(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles cmdAddLine.Click
>lstLines.Items.Add(PhoneFormat(txtAddLine.Text))
>txtAddLine.Text = ""
>setFocus(txtAddLine)
>End Sub
>Public Sub setFocus(ByVal ctrl As System.Web.UI.Control)
>Dim strS As String
>strS = "<SCRIPT language='javascript'>document.getElementById('" +
>ctrl.ID + "').focus();</SCRIPT>"
>RegisterStartupScript("focus", strS)
>End Sub
>This will not place the focus in the textbox. What am I missing?
>Again, PLEASE help. Thanks much!
Put a blank label at the bottom of the form and set its text property
in the codebehind instead of using the registerstartupscript.
-Adam
:o) You're all wrong. I took and made a clean application and it
worked, so I knew it wasn't the code there. I went back to my app,
(made a copy) and proceded to strip everything out until it worked.
Well, after everything was gone it still didn't work. There was only
one remaining thing, smartnavigaion = true.
That fixed the focus problem by turning it off, however it introduced a
whole new set of problems.
Having a database application, the users need to not use the back
button. I've got all the standard code for this but it's still not as
clean as smartnav.
Is there ANY way to overcome smartnav's focus problem?
MICROSOFT'
I didn't think so.
Anyhow, I've solved one problem only to intoduce many more. I may have
more ?'s soon, some really good ones I've been working on. Thanks for
the help so far.
Jeff
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!