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

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

listView - ItemDataBound event - problem casting to DataRowView to get to underlying data?

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

System.InvalidCastException was unhandled by user code
  Message="Unable to cast object of type 'WebSTAR.JobListItem' to type 'System.Data.DataRowView'."
       at WebSTAR.Default.ListViewRecentJobs_ItemDataBound(Object sender, ListViewItemEventArgs e) in C:\Users\djc\Documents\Visual Studio 2008\Projects\WebSTAR\WebSTAR\Default.aspx.cs:line 255
       at System.Web.UI.WebControls.ListView.OnItemDataBound(ListViewItemEventArgs e)

View Complete Post

More Related Resource Links

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:)

ListView ItemDataBound Event



I want to access a dropdown control value of each list item as soon as it is created. I tried with ItemCreated and ItemDataBound events but I am getting null contro when I try to access control as shown below:

ListViewDataItem item = (ListViewDataItem)e.Item;

int LstIndex = item.DataItemIndex;

RadComboBox ddlCategory = (RadComboBox)(listView1.Items[LstIndex].FindControl("rdComboCategory"));

Also, I get listview.item.count zero. IS there any event where I will get listitem count and list items?

Using ASP.NET 3.5's ListView and DataPager Controls: Displaying Data with the ListView

Prior to ASP.NET 3.5, developers who needed to display a set of records could choose between the GridView, DataList, and Repeater controls. The GridView provides rich data features, but has a very boxy layout; the DataList and Repeater allow for a more flexible layout, but lack the "point and click" data features found in the GridView, DetailsView, and FormView controls. The ListView bridges the gap between layout flexibility and built-in data features.

This article, the first in a series of articles on the ListView and DataPager controls, looks at the ListView's many available templates and illustrates how to display data. Read on to learn more!

ListView DataPager with SQL-Statements that already return only paged data.



As far as I understand the ListView-Control and the DataPager-Control, they work like this: The ListView gets its datarows from its data source, then the DataPager causes the ListView to display only a subset of those rows.

So what, when I want to use custom databinding for the ListView, that *already* gets the certain subset from SQL-Server (for better performance). Can I and how can I use the DataPager then?

Thanx, S.

MySql.Data assembly problem



I added refernece MySql.Data to my project. My web.config looks like that:

<?xml version="1.0"?>
                <add assembly="MySql.Data, Version=, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/>

But when in ServerExplorer I try "Add Connection..." I can't find "MySql Database" in the "Choose Data Source" dialog box?

What the problem can be?

problem...i want a list item to populate all data in gridview!!!


i have a dropdownbox and a gridview

what I want is to have a list item which populates all data in a gridview.

I have tried using list item selected value=0 but to no avail.

what is the easiest way to achieve this?

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?


Ajax Accordion to load data from client click event


I have a Ajax Accordion control on my page with treeview in Content Template. As the treeview for each pane are big. I am wondering whether I can load the treeview from codebehind only after the pane is selected. I can reuse the code from ItemDataBound of Accordion control.

Pre_Init event handler problem


Hi all my friends

   I have to masterpages for my home page.

1. The first is for the annonymous users which has the login controls. its name is General_Anonymous.master.

2. The second one is for the logged in users which has a logout button and it hasn't the login controls in it. its name is General_LoggedIn.master.

in my default.aspx page I wrote the following code

protected void Page_PreInit(object sender, EventArgs e)
            if (Session["SupId"] == null && Session["CustomerId"] == null)
                this.MasterPageFile = "~/Masters/General_Anonymous.master";
                this.MasterPageFile = "~/Masters/General_LoggedIn.master";

Nested listview fk-problem with insert



My problem is this, i have a nested listview that works fine but if i need to do an insert and the nested listview dont have retrived any values (that is no posts created) i cant get hold of the fk that i need. If i put a hiddenfield in the parents listview with the fk how can i find it in codebehind when i do an insert? 



Visual Studio designer event problem


Hi there

I have a small issue that I'm sure others have experienced - but haven't yet found a solution / workaround for this.

When adding controls to Visual Studio in designer you normally get a event button (the yellow flash light) in the properties window.

But when you nest a button inside a placeholder (for example) you cannot mark the button from the designer - only the placeholder! When trying to go into "split-view" on the designer you'll be able to mark the button in the bottom of the designer - but only properties and not the event button appers in the properties window!

I know that you can go into codebehind and manually add the event but I thiink it is really tiresome to do so if I don't have to...

I had a small hope that VS2010 the issue would be gone but sadly it isn't...

Anyone ever found a solution for this one?

Kind regards Thomas

CheckedListBox displays System.Data.DataRowView on one machine

As I was writing this post I solved my problem. Now I will share the solution for anyone who may stumble across this legacy cr*p. I inherited an old VB.NET application written in the old Visual Studio .Net against the 1.0 framework. Recently we had to rebuild a couple of machines and redeploy the app. We have CheckedListBox controls bound using the DataSource property and suddenly all we could see was System.Data.DataRowView in the list on these machines. All the forums out there tell you that binding the items with the DataSource property is not supported by Microsoft and offer code fixes, which we obviously do not want to do. I installed the .Net Framework 1.0 redistributable and fixed it right up. Which is a little strange because one of the machines it still works on only has 1.1. But there you have it  I actually tested this on another machine by installing 1.1 first, which did not fix the problem, but installing 1.0 did. And another interesting thought. The executable and its class library dependency reside in a network share. After installing the 1.0 framework I had to run a Caspol.exe command to grant privs to the share or the executable could not access the library. The app functioned fine without the Caspol.exe command (except the ListBox of course) prior to installing the 1.0 framework. Strange stuff...Hope this helps someone someday.

Data Mining solution - SSRS Problem

I have created a Data Mining - Time Series solution and I am getting proper results from SSAS(Mining Model prediction tab) & SQL Management Studio query. However when I try to create an report using SSRS, In the field where I am expecting the predicted value, I am getting "#Error" Any suggestions as why this is happening.

A layout, mouse selection, ListView problem/question

I'm having a problem with a particular layout scenario, and how it interacts with a left mouse click in certain situations. I have 3 rows in a Grid.  The first is a ListView (Master), with the Row Height set to '*'. It's ItemSource is bound to a collection in a ViewModel, and its SelectedItem is bound to a value in the ViewModel.  When the SelectedItem is null, it should take up its entire container (the other 2 rows are invisible). The second row is the GridSplitter.  It's visibility is bound to a value in the ViewModel.  It's only visible when the SelectedItem in the Master ListView is not null.  It's GridRow height is set to Auto, and it's height is explicitly set to 5 (via a style). The third row is a sub-ListView that shows Detail data for the Master SelectedItem in the top ListView.  It's GridRow Height is set to zero by default, and if an item is selected in the Master ListView, it should become visible and have a set height (400 to start, via a binding on the Height of the row). The desired effect is that when an item is selected in the Master ListView, the Detail ListView becomes visible and the GridSplitter allows you to resize the top and bottom as needed.  If necessary, the ScrollBars become visible in the Master ListView to show any items that are now obscured by the Detail ListView (via the automatic scrolling featur

Sharepoint 2010 List Added Event Problem

Hi All, I have created List Added Event Handler. In that Event I want to Add Custom Field in List as List is created. I get an Error "The Specified Program Requires    a newer version of windows" Is there ant solution for it. I have tried it also creating new instances of spweb and spsite rather than getting it from "Properties" Thanks Saumil Thakkar

wpf charting column series data binding problem

I'm trying to build a chart using the columnSeries from the wpf toolkit and I appear to be having trouble with the data binding. Here is the xaml: <Grid>    <chartingToolkit:ColumnSeries Height="18" HorizontalAlignment="Left" Margin="188,169,0,0" Name="columnSeries1" VerticalAlignment="Top" Width="18" IndependentValueBinding="{Binding Path=Date}" DependentValueBinding="{Binding Path=Value}" /></Grid> In the code behind, I'm calling a stored procedure and putting the result in a datatable like this: string connString = ConfigurationManager.ConnectionStrings["string"].ConnectionString;            using (SqlConnection cn = new SqlConnection(connString))            {                DataTable dt = new DataTable("T1");                cn.Open();                SqlCommand cmd = new SqlCommand("T1_sp", cn);                cmd.CommandType = CommandType.StoredProcedure;                  SqlDataAdapter da = new SqlDataAdapter(cmd);                da.Fill(dt);                columnSeries1.ItemsSource = dt.DefaultView;                cn.Close();            } No error is being generated but I'm not getting a column chart either. If I take the same command and put it into a datagrid, it works fine. What do I need to do to get this into my column chart? If it helps,

Problem with listview selection

I have the following problem (which I have seen documented in many places with no solution).  I populate a listview.  The steps I use are: Set the ItemsSource to nothing (VB) Set the ItemsSource to the collection to be bound to Set the selected item to nothing (VB) Set the selected item to the first item in the collection The problem is that when I use the down arrow key to change selection in the listview, the first time I use the down arrow nothing happens.  After that first glitch everything works.  I have seen many "solutions" but none that work. Any ideas?? Thanks LLoyd Sheen
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