Showing posts with label rows. Show all posts
Showing posts with label rows. 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"

Saturday, March 24, 2012

Set Focus and post back on Dropdown List

I have a dropdown list that hides certain rows in a datagrid.

The focus remains on the dropdown list after the postback and I am trying to get it away from it because the user may and does want to use the mouse wheel to scroll down, but since the focus is on the ddl, they may not see it and it will resort.

Here is my set focus code which works fine on page load event...


Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
Dim s As String = "<SCRIPT language='javascript'>document.getElementById('" & ctrl.ID & "').focus() </SCRIPT>"
RegisterStartupScript("focus", s)
End Sub

And this code is for the page load event...


If Not IsPostBack Then
Me.SetFocus(Me.txtSearch)
End If

I have been trying to place the Me.SetFocus(Me.txtSearch) where the postback of the ddl occurs in the code, such as the reBind() or the ddlTypes_SelectedIndexChanged() and the dgServer_ItemDataBound() which has the ddl code.
None seem to work, but it works on page load event.

Suggestions?

Thanks all,

Zath
This should work fine from your ddlTypes_SelectedIndexChanged() event handler. Are calling this method only if the IsPostBack property is false? If so, that could be your problem.

Have you tried putting the SetFocus in the Page_PreRender? This runs after the event code.


Private Sub Page_PreRender(ByVal sender AS Object,VyVal e AS System.EventArgs) Handles MyBase.PreRender
If ispostback=true then
Me.SetFocus(Me.txtSearch)
End if
End Sub

You can use
If Not ispostback
if necessary.
check out my component here :view post 821121

regards

Set focus to DAtagrid Cell

I hae a WEB application that uses a datagrid. My first 2 rows are Template
columns with Dropdown lists. My Third column as databound cell. When I go
to edit a particular row I want the focus to change to the third row. I am
using Visual Studio VB.Net with WEB Forms. Any Help would be great.It is not clear what exactly you want. Anyway, setting focus is a
client-side task. You have to produce some javascript which will operate on
the client DHTML presentation of the grid.

Eliyahu

"rroca" <oeb@.homexperts.net> wrote in message
news:C3CD2487-6FD7-4830-A20D-E14E18CA56F1@.microsoft.com...
> I hae a WEB application that uses a datagrid. My first 2 rows are
Template
> columns with Dropdown lists. My Third column as databound cell. When I
go
> to edit a particular row I want the focus to change to the third row. I
am
> using Visual Studio VB.Net with WEB Forms. Any Help would be great.

Set focus to DAtagrid Cell

I hae a WEB application that uses a datagrid. My first 2 rows are Template
columns with Dropdown lists. My Third column as databound cell. When I go
to edit a particular row I want the focus to change to the third row. I am
using Visual Studio VB.Net with WEB Forms. Any Help would be great.It is not clear what exactly you want. Anyway, setting focus is a
client-side task. You have to produce some javascript which will operate on
the client DHTML presentation of the grid.
Eliyahu
"rroca" <oeb@.homexperts.net> wrote in message
news:C3CD2487-6FD7-4830-A20D-E14E18CA56F1@.microsoft.com...
> I hae a WEB application that uses a datagrid. My first 2 rows are
Template
> columns with Dropdown lists. My Third column as databound cell. When I
go
> to edit a particular row I want the focus to change to the third row. I
am
> using Visual Studio VB.Net with WEB Forms. Any Help would be great.