asp.net ListView Item Control instance

Source: Internet
Author: User
Tags eval oracleconnection

ASP tutorial. NET ListView Item Control instance
The form is designed to place a ListView control on a form, and then place a ImageList (ImageSize (50,40)) control and select ListView's LargeImageList property, And then place a TabControl control
When I load the form, I execute the following code to add the item to the ListView, the following code

for
(int i = 0; i < i++)
{
ListViewItem lvi=new ListViewItem ();
Lvi. Text = DateTime.Now.AddDays (i). ToString ("MM month DD day");
Lvi. ToolTipText = dt Initial display time. AddDays (i). ToString ("Yyyy-mm-dd");
LSV Subscription status. Items.Add (LVI);
}

This is the repaint code.

private void Listview1_drawitem (object sender, DrawListViewItemEventArgs e)
{
Rectangle rect = e.bounds;
Rect. Width = rect. Width-3;
if ((E.state & listviewitemstates.selected)!= 0)
{
Change the selected background color
E.graphics.fillrectangle (New SolidBrush (Color.FromArgb (215, 232, 252)), rect);
Draw Border
E.graphics.drawrectangle (New Pen (Color.FromArgb, 162, 206)), Rect);
}
Else
{
Default background color
using (SolidBrush Bbrush = new SolidBrush (color.white))
{
E.graphics.fillrectangle (Bbrush, rect);
Draw Border
E.graphics.drawrectangle (New Pen (Color.FromArgb, 162, 206)), Rect);
}
}
if ((ListView) sender). View!= View.Details)
{
Font ft = new System.Drawing.Font (Fontfamily.genericsansserif, 9);
SolidBrush Fontbrush = new SolidBrush (Color.Blue);
StringFormat Format = new StringFormat ();
Format.alignment = Stringalignment.center;
E.graphics.drawstring (E.item.text, FT, Fontbrush, new RectangleF (rect). Left, rect. TOP+10, Rect. Width, Rect. Height), Format);
Ft. Dispose ();
Fontbrush. Dispose ();
}

}
ListView Usage Learning
<asp:listview runat= "Server"
Id= "_simpletablelistview"
Datasourceid= "_moviesdatasource" >
<LayoutTemplate>
<ul>
<asp:placeholder runat= "Server"
Id= "Itemplaceholder"/>
</ul>
</LayoutTemplate>
<ItemTemplate>
<li><%# Eval ("title")%>
<%# Eval ("Release_date", "{0:d}")%> </li>
</ItemTemplate>
</asp:ListView>

And look at a ListView complete example

Public Frm_manage ()
{
InitializeComponent ();

String ConnectionString = "Data source=dzjc_2005;user=kk;password=kk;";/ /write Connection string
OracleConnection conn = new OracleConnection (ConnectionString);//Create a connection

Conn. Open ();
OracleCommand cmd = conn. CreateCommand ();
Cmd.commandtext = "Select U_name from Netvideo.n_user";//write SQL statements here
OracleDataReader dr = cmd. ExecuteReader ()//Create a Oracledatereader object

Listview1.gridlines = true;//Show divider line between row and row
Listview1.fullrowselect = true;//to choose is one line
Listview1.view = view.details;//Define how the list is displayed
Listview1.scrollable = true;//need time to display scroll bars
Listview1.multiselect = false; No more lines to select
Listview1.headerstyle = columnheaderstyle.clickable;

The field name for the database tutorial, set up to fit the display header
LISTVIEW1.COLUMNS.ADD ("operator name", 282, HorizontalAlignment.Center)//First argument, table header, 2nd argument, table header size, 3rd parameter, style
listview1.visible = True;//lstview Visible

while (Dr. Read ())
{
ListViewItem Item = new ListViewItem ();
Item.SubItems.Clear ();

Item.subitems[0]. Text = dr["U_name"]. ToString ()//Read a field in the database

LISTVIEW1.ITEMS.ADD (Item)//Display
}
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.