.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

trying to select non-existent node in listview databound event icw xmldatasource

Posted By:      Posted Date: October 08, 2010    Points: 0   Category :ASP.Net

Protected Sub repLocationsToCompare_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles repLocationsToCompare.ItemDataBound

Dim enumerable As IEnumerable = System.Web.UI.XPathBinder.Select(e.Item.DataItem, "./str[@name=""thumb""]")

Now, it might be that the current dataitem does NOT contain the <str name="thumb"></str> node. So in that case when I do this:
Dim name As String = enumerable.Cast(Of XmlElement)().Select(Function(x) x.Attributes("name")).FirstOrDefault().Value
the enumerable throws an error of object reference not set to instance of object.

I tried testing it like this:
Dim enumerable As IEnumerable = System.Web.UI.XPathBinder.Select(e.Item.DataItem, "./str[@name=""thumb""]")
if enumerable isnot nothing then
Dim name As String = enumerable.Cast(Of XmlElement)().Select(Function(x) x.Attributes("name")).FirstOrDefault().Value
end if

But still I get the error.

How can I test if the node exists for the current dataitem?

View Complete Post

More Related Resource Links

Programmatically Simulating the ListView's ItemCommand Event


I have a User Control that contains a ListView.  In the user control's code is this event handler:

    protected void listView1_ItemCommand(object source, ListViewCommandEventArgs e)
      Button_ClickHandler(source, e);

What's occurring is that I'm explicitly firing an event so that the parent web page can monitor this and take appropriate actions.  Thus when the user clicks on a different ListViewItem it triggers the population of associated data elsewhere on the web page.

This all works fine except for one thing: When I first load the control I'm pre-setting the first ListViewItem.  Unfortunately, just setting the ListView's SelectedIndex = 0 doesn't fire the aforementioned event handler.

So I started investigating how to call "listView1_ItemCommand" but couldn't figure out how to instantiate the "e" parameter.

Any ideas of how to resolve this?


Custom Grid View Header - Grid view Row Created event vs Gridview row databound events ?


Hi Gurus ,

It happened to add an extra Gridveiw Header in row_databound event , It did worked fine on !Postback but disappered on Page.Postback . Quick google search guided me to move the event to Row_Created event and every thing is okay .

Can any expert post some pointers , differnces between grid row_created vs row_databount with some sample table data created dynamically  behaviour of both the events in !Postback and page.Postback .

Thanks a tonne in Advance and  any inputs will be valued and appreciated .

Can't change Gridview row colors or styles in the DataBound event


I was highlighting certain rows in my gridview using code like this in the DataBound event:

        if (e.Row.RowType == DataControlRowType.DataRow)
            int vendorCheck = 0;
            //TODO make this shorter
            if (DataBinder.Eval(e.Row.DataItem, "vendorId") != System.DBNull.Value)

listview with button in item template - how do I handle the click event?

Hello,Using a listview control for the first time... I need a button for each item, and of course I need to handle the click event for the buttons... upon clicking a particular button I of course need to know which item the button is associated with so the appropriate action can be taken...In VS, I can't select the button and see my list of available events in the properties window like is normally done for controls outside of templates like this... what do I need to do?

Treeview node to add onclick event to download files

 Hi, I would like to know how to add onclick evend to a TreeNode so that the file can be downloaded.   How can I implement below sample code to a TreeNode? <a href="#" onclick="popup('/directory1/Somefile.doc'); return false;" target="download"> Somefile </a> <script language="javascript"> function popup(url) { popWin = window.parent.open(url, 'popWindow', 'height=900, width=900, toolbar=no, menubar=yes, scrollbars=yes, titlebar=no, resizable=yes,location=0, directories=no, status=no'); } </script> I have TreeNodePopulate event to populate nodes like this: protected void DocRepository_TreeNodePopulate(object sender, TreeNodeEventArgs e) { .... String[] files = Directory.GetFiles(fullPath); foreach(String file in files) { TreeNode newNode  = new TreeNode(Path.GetFileName(file), Path.GetFileName(file)); node.ChildNodes.Add(newNode); } }   Thank you in advance.              

checkbox in listview layout template check select all checkboxes in listview itemtemplate

hi,how to do this when the checkbox in listview layout template check select all checkboxes in  listview itemtemplate.I dont give 'Eval 'field to checkbox present in itemtemplate.pls reply me.Many thanks in advance.

how to select the Tree node value & text using javascriot or Jquery

how to select the Tree node value & text using javascriot or Jquery

How to select some part of a text in listview item?


Dear all

I have a listview in WPF application, that I bind data in it using gridview. now I want to make a search for it. making search is simple but question is this I want to make a search that if user type 'a' then system will highlight all 'a' in list view. or if user type 'lis' the system will highlight all 'lis' in that listview.

Is it possible to highlight part of the text in side of listview item? or I have to select whole listviewitme? 


Thank you so much

ListView DataBound


I am using ListView to display the Data.


I am getting some text or empty string from backend for a particular colummn.

If i got empty string i need to bind with an imageButton in that row.

and if i got a text i need to replace the imagebutton with text.

protected void lv_DataBound(object sender, EventArgs e)






Thanks in Advance.

ListView, DataPager, LinqDataSource: LinqDataSource Selecting event fire twice


Dear all,

In my web app, I used LinqDataSource, ListView and DataPager (.NET 3.5 sp1) to implement search feature with paging. I have a button to trigger the search.

But In the first time, the Selecting event of LinqDataSource fire twice and I don't know why (I debugged my code very carefully). I don't use QueryString with DataPager and assign PageSize of DataPager in the first time of page load to prevent the ListView bind again (as in some instructions I found in forum)

Have anyone seen this problem before? And If possible, can you give me some instructions to try?

I can't post my code because it's quite large.

Thank you very much


Developer, CSC Vietnam


How to handle treeview selected node changed event



From my below sample code, I don't want to use Sessions to handle each click event inside treeview selected node changed.

Secondly, if you suggest me to use treenode.SelectedValue then I would say my values are dyanmically generated.

Everytime a node a clicked, the selected node value is sent in the next request xml to get response and xml schema is different for each click. How do I handle this each click event other than using session variables. I thought of using Request.Item (and integrating with URL redirect property) but I don't want to use that.


Dim trNode As New TreeNode
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then        
            trNode.Text = "Not Postback"
            Session("Flag") = 1
        End If
    End Sub

Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TreeView1.SelectedNodeChanged
        If Session.Item("Flag") = 1 Then
            trNode.Text = "Is PostBack"
            Session("Flag") = 2
        End If

Databound Hyperlinks in ListView. Need to open external sites


Good Evening,

This site is ASP.NET 4.0 connected to a SQL 2005 backend.  The database has a table that, among other things, lists the names and URIs of external sites for reference purposes.  A webform has a ListView control bound to an ObjectDataSource that pulls the data from this table.  The ItemTemplate and the AlternatingItemTemplate have been edited so that they contain this HyperLink:

                            Text="Route Map" 
                            NavigateUrl='<%# Eval("Maplink") %>' />

The page renders the data normally but the HyperLinks aren't working as intended.  For example, the datatable record might contain
But when the HyperLink is created in the ListView, it comes out as:
which, of course, fails.

How can I set up the HyperLink to route to the external site and ignore the local domain path?

Thanks for any suggestions. 


Create column In Datalist On DataBound Event


Hi ,

 I have a condition on which i have to set the column of the datalist at run time.

IT may be 2,3 or 4 at run time.

How i do it. plz replay as soon as possible.

Is this possible that on the item bound event i set the html <tr><td>.

IF Yes Then How.


Selection Changed event is not firing for listview



     In my listview i have two columns, once is check box and another one is normal column. if i select in normal column, listview's selection changed event is fring, but when i select check box(This checkbox is inside the datatemplate) listview's selection changed event is not firing. Can any one tell me how i can achieve it. If you are not understand, please give your email id, i will send my sample application to you.



Udayakumar S

Problem with ListView' SelectionChanged event


I have a listview (C#) with some items representing metadata objects. Near this listview I have a Panel where the structure of selected metadata object is shown.

When user selects one item I want to show my Panel (with structure of this item).

When user doesn't select any item or selects many items I want to hide my Panel.

It works but there are a lot of blinks during selection changes. I've prepared workaround to this issue by checking in SelectionChanged event whether the number of selected items changed (none -> one, one -> many, many -> one, one -> none). If the number changed so I show or hide the panel, in other cases I don't do anything.

But one blink is still here. When I just move one-item selection from one item to another then SelectionChanged occures 2 times (for previous selected item and then for next selected item). So my check works incorrectly in this case: one item selection changes to none selection (first SelectionChanged event) and panel becomes hidden, then none selection changes to one item selection (second SelectionChanged event) and panel becomes shown. So user sees blinks.

How can I detect whether user deselected all items at all or just moved the selection from one item to another.

Thanks a lot. Sorry for my English:)

Nested ListView: Parent listview item auto selection on child ListViewitem select


how can i auto select paraten listview item on selecting child listview item?

ListView ItemContainerStyle="{StaticResource myStyle}" Name="lv_list" Margin="5" HorizontalContentAlignment="Stretch">

DataBound Event not firing for MS Chart



DLL: System.Web.DataVisualization.dll (File Version - 3.5.30729.116)

Namespace: System.Web.UI.DataVisualization.Charting;

Class: Chart

.NET Version: 3.5 SP1


I have a chart control and I am using to following to add some additional code to the DataBound event.

this.DataBound += new EventHandler(Chart_DataBound);

protected void DSEChart_PreRender(object sender, EventArgs e)

void Chart_DataBound(object sender, EventArgs e)


      //Performing some action here


In the code behind on the page I call the DataBind() method for this control, however, it is not firing t

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend