asp.net - How to dynamically assign datasource to listview -


I have a problem with the data source dynamically in the list view.

For example, I have a list of bonuses received

Research on Internet and stackoverflow.com I found 3 solutions:

    (bonus), received layout ( Skip) and I want to display list list those list items which click on the link button user.
  1. Using repeaters inside the list view but in my case, I could not apply it in my case and I became totally confused

  2. Using the nested list view I tried to:

  & lt; Asp: ListView id = "Bonus" runat = "server" datasource = '& lt;% # Eval ("received_bone")% & gt; & Gt; & Lt; ItemTemplate & gt; & Lt; TR & gt; & Lt; Td> & Lt;% # Eval ("bonus_desc")%> & Lt; / Td> & Lt; Td> & Lt;% # Eval ("bonus_type")%> & Lt; / Td> & Lt; / TR & gt; & Lt; / ItemTemplate & gt; & Lt; LayoutTemplate & gt; & Lt; Table & gt; & Lt; TR & gt; & Lt; Th & gt; Bonus details & lt; / Th & gt; & Lt; Th & gt; Date received & lt; / Th & gt; & Lt; / TR & gt; & Lt; Tr id = "item placeholder" runat = "server" /> & Lt; / Table & gt; & Lt; / LayoutTemplate & gt;  

  & lt; Table & gt; & Lt; TR & gt; & Lt; Th & gt; Bonus details & lt; / Th & gt; & Lt; Th & gt; Date received & lt; / Th & gt; & Lt; / TR & gt; & Lt; Tr id = "item placeholder" runat = "server" /> & Lt; / Table & gt; & Lt; / LayoutTemplate & gt; & Lt; / ASP: ListView & gt; & Lt; Br / & gt;  

And on the code I tried to write like this: Secure Zero DataBound (Object Sender, ListViewItemEventArgs e) {this.DataBindChildren ();

He has not given any errors, which do not work.

    I do not know how to apply it in my case.

    Any help is appreciated.

    Thank you very much.

You have to change datasource from the server or call the ListView on DataSourceID property and DataVind.

You have to make sure that when using the & lt;% # Eval ("")%> syntax you are binding the objects that are named in those properties. Therefore, when your properties are connected with type names and underscores, you may have problems with switching data sources. After saying this You have two options that change a data source. In the event of a click of a button or whatever you are using the switching mechanism, you can just write something.

Not using the data source in the markup:

  list & lt; Bonus & gt; Bonus List = GetBonuses (); MyListView.DataSource = bonusList; MyListView.DataBind ();  

Use of a datasource in the markup:

  // Where the markup in the bonus list will be the ID of the data source MyListView.DataSourceID = "BonusList"; MyListView.DataBind ();  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -