In ListView, SubItems

patrick

Well-known member
Joined
Dec 5, 2021
Messages
305
Programming Experience
1-3
In ListView, SubItems
Subitem is not recognized in listview.



que.png
 
A Windows Forms ListView and a Web Forms ListView are different controls. Code that works for one will not necessarily work for the other. If you're creating an ASP.NET Web Forms app then you need to learn how the ASP.NET Web Forms ListView control works, rather than basically just copying code written for the Windows Forms ListView.
 
A Windows Forms ListView and a Web Forms ListView are different controls. Code that works for one will not necessarily work for the other. If you're creating an ASP.NET Web Forms app then you need to learn how the ASP.NET Web Forms ListView control works, rather than basically just copying code written for the Windows Forms ListView.

I using ASP.NET Web form.

I am converting From the code of the winform ListView To the code of the webform ListView.

I'm working on a code migration.


How do I convert ListViewItem SubItems to ASP.NET?

There aren't many examples of ListView in ASP.NET on the Internet.

There is no time to self-study on asp.net listview from the basics.


que.png
 
Last edited by a moderator:
I know you are. That's why writing code for a WinForms control is useless. It's like you didn't even read the words I wrote. I didn't provide a link to the Web Forms ListView control documentation for my health.
 
I know you are. That's why writing code for a WinForms control is useless. It's like you didn't even read the words I wrote. I didn't provide a link to the Web Forms ListView control documentation for my health.

Can't migrate Winfom ListView Code to Webform ListView Code?
 
Obviously not. There will be similarities but they are not the same. You need to learn how the Web Forms control works and then try to write appropriate code. If what you write doesn't work, we can help you fix it.
 
Obviously not. There will be similarities but they are not the same. You need to learn how the Web Forms control works and then try to write appropriate code. If what you write doesn't work, we can help you fix it.

I don't know which function to migrate from asp.net to the functions ( SubItems, Color, Add, SelectedItems, SelectedItems[].SubItems[], Clone)
in the code below.
Please teach me the function ASP.NET that can replace ( [ In WinForm] SubItems, Color, Add, SelectedItems, SelectedItems[].SubItems[], Clone ).


C#:
                ListView listAssign; // Declaration

                // Initialization ListView
                ((ListView)listAssign).View = View.Details;
                ((ListView)listAssign).FullRowSelect = true;
                ((ListView)listAssign).GridLines = true;


                ListViewItem item;
                item = new ListViewItem("Apple"));
                item.SubItems.Add("Banana");        //========= SubItems
                item.SubItems.Add("Strawberry"); 
 
                item.BackColor = Color.DarkOrange;   //========= Color

                listAssign.Items.Add(item); // ========== Add


                // Function
        private void btnDetach_Click(object sender, EventArgs e)
        {
                for(int i=0; i< listAssign.SelectedItems.Count; i++) // =============== SelectedItems
                {
                    if(!listAssign.SelectedItems[i].SubItems[1].Text.Equals("Apple")) //============ SelectedItems[].SubItems[]
                    {           
                        return;
                    }
                }

                ListView lvOriginal = new ListView();
    
                foreach (ListViewItem item in listAssign.Items)
                {
                    ListViewItem it = (ListViewItem)item.Clone(); //=================== Clone
                    lvOriginal.Items.Add(it); //================= Add
                }
 
        }



The HTML source below is for reference.


C#:
                                                        <asp:ListView ID="listAssign" runat="server" Visible ="true">

                                                            <LayoutTemplate>
                                                                <table border="0px" cellpadding="1">
                                                                    <tr style="background-color: #E5E5FE">
                                                                        <th>firstname</th>
                                                                        <th>lastname</th>
                                                                    </tr>
                                                                </table>
                                                            </LayoutTemplate>
                                                            <ItemTemplate>
                                                                <tr>
                                                                    <td>
                                                                        <asp:Label ID="txtFName" Text='<%#Eval("FName") %>' runat="server"></asp:Label></td>
                                                                    <td>
                                                                        <asp:Label ID="txtLName" Text='<%#Eval("FName") %>' runat="server"></asp:Label></td>
                                                                </tr>
                                                            </ItemTemplate>
                                                        </asp:ListView>
 
Last edited by a moderator:
There is no time to self-study on asp.net listview from the basics.
If you are doing this as a contract job, you shouldn't have accepted the contract, or built in time to learn.

If this is not a contract job, talk to your manager and tell them that you need time to learn, or need training.

Anyway, the link below should give you a crash course that is a little bit friendlier than the MSDN documentation. After going through the crash course below, I would recommend still taking time to read the documentation because there are other things worth learning in the documentation that is not in the link below.

 
Last edited:
If you are doing this as a contract job, you shouldn't have accepted the contract, or built in time to learn.

If this is not a contract job, talk to your manager and tell them that you need time to learn, or need training.

Anyway, the link below should give you a crash course that is a little bit friendlier than the MSDN documentation. After going through the crash course below, I would recommend still taking time to read the documentation because there are other things worth learning in the documentation that is not in the link below.



thank you for your teaching
 
If you are doing this as a contract job, you shouldn't have accepted the contract, or built in time to learn.

If this is not a contract job, talk to your manager and tell them that you need time to learn, or need training.

Anyway, the link below should give you a crash course that is a little bit friendlier than the MSDN documentation. After going through the crash course below, I would recommend still taking time to read the documentation because there are other things worth learning in the documentation that is not in the link below.

I do not use data from DB.
The way you taught me is to DataBind() the DB.
I add each string data individually to the listview. So SubItem, Add concept is used.
I don't know SubItems, Add in Listview ASP.NET WebForm.

No matter how much I search on the internet, I can't find any ASP.NET Webform listview example data.
 
I do not use data from DB.
The way you taught me is to DataBind() the DB.
So use an ObjectDataSource instead of a SqlDataSource. You're allowed to put your own thought into it rather than just copying whatever you see on the web.
 
So use an ObjectDataSource instead of a SqlDataSource. You're allowed to put your own thought into it rather than just copying whatever you see on the web.
My Question is Subitems, ADD, SelectItems in aps.net webform listview.

I MIGRATE from c# listview TO ASP.NET LISTVIEW CODE
 
Last edited by a moderator:
It seems like you haven't got the message yet so I'll just say it outright. We're not here to do your work for you. Sites like this are to get help with the stuff you can't work out for yourself, not stuff you can't be bothered to work out for yourself. If you're prepared to make an effort and run into an issue then we'll be happy to help. If you want us to write your code for you, you'll be disappointed.
 

Latest posts

Back
Top Bottom