Showing posts with label item. Show all posts
Showing posts with label item. Show all posts

Wednesday, March 28, 2012

Programmatically Select a listview item

Can't seem to figure out how to do this. The listview class browser doesn't list much in the way of an API call to do this. Anyone know if this is possible?Did you figure this out?

ListView.SelectedListViewItemCollection listViewItemCollection = this.ListView1.SelectedItems;

foreach ( ListViewItem item in listViewItemCollection)
{
//Your code goes here
}


ListView1.Items(0).Selected = True
ListView1.Select()

The first line indicates what item is to be selected, and the second line is what actually selects it. The most common mistake is leaving out the second line.

Saturday, March 24, 2012

Question about OnClientClick for asp:LinkButton...

I have the code:

Code Behind .vb file:

Dim lbAsNew LinkButton

lb.Text = dt.Rows(j).Item(

0)

lb.ID =

"cat" +CType(dt.Rows(j).Item(1),String)

lb.CssClass =

"lbH1"

lb.OnClientClick =

"lb_Click('" +CType(dt.Rows(j).Item(1),String) +"')"

tc.Controls.Add(lb)

Client Side .aspx file:

<scriptlanguage="javascript"type="text/javascript">function lb_Click(e){

alert(e);

}

</script>

How can I tie this code in to talk to a Page Method or WebService? Any good simple links/tutorials? I tried the Ajax video page but apparently the sound drops out half way through the video? And my books refer to 'Atlas' instead of 'Ajax 1 or 2'.

You can add a onclick event handler like this:

AddHandler lb.OnClick, AddressOf lb_Click

And define a event handler method as below:

Protected Sub lb_Click(sender as object, E as EventArgs)

End Sub

If want to execute it asynchronously, you can decorate the above method with WebMethod attribute. Like this:

<WebMethod()> Protected Sub lb_Click(sender as object, E as EventArgs)

End Sub