ASP.NET (C#)listview控件怎么用呀?
最近在做一个系统,用listView控件绑定数据库数据,但在做更新动作时总是无法获得指定label的值,导致无法完成操作!有那位大虾可以给一个有关自定义ListView删...
最近在做一个系统,用listView控件绑定数据库数据,但在做更新动作时总是无法获得指定label的值,导致无法完成操作!有那位大虾可以给一个有关自定义ListView删除,更新,添加的例子(与数据库数据进行绑定),将感激不尽!急!
当我把这个问题提出来时,我却找到了原因,并且很快解决了!
不过还是要对各位说声:谢谢! 展开
当我把这个问题提出来时,我却找到了原因,并且很快解决了!
不过还是要对各位说声:谢谢! 展开
3个回答
展开全部
可以直接绑定数据库数据
class Xshow : ListView
{
public event EventHandler<DragEventArgs> XDragDrop;
public Xshow()
: base()
{
base.AllowDrop = true;
base.View = View.Details;
base.FullRowSelect = true;
base.ColumnClick += new ColumnClickEventHandler(Xshow_ColumnClick);
base.DragEnter += new DragEventHandler(Xshow_DragEnter);
base.DragDrop += new DragEventHandler(Xshow_DragDrop);
Columns.Add("Path",500);
}
class SortType : IComparer
{
int _subcolIdx;
bool _descending;
public int SubcolIdx
{
get { return _subcolIdx; }
set { _subcolIdx = value; }
}
public bool Descending
{
get { return _descending; }
set { _descending = value; }
}
public SortType(int subcolIdx)
{
_subcolIdx = subcolIdx;
_descending = false;
}
public int Compare(object a, object b)
{
ListViewItem x, y;
if (_descending) { x = (ListViewItem)b; y = (ListViewItem)a; }
else { x = (ListViewItem)a; y = (ListViewItem)b; }
//SubItems[0] == item in first row, SubItems[1]=first subitem
return String.Compare(x.SubItems[_subcolIdx].Text, y.SubItems[_subcolIdx].Text);
}
}
void Xshow_DragDrop(object sender, DragEventArgs e)
{
string[] ss = (string[])e.Data.GetData(DataFormats.FileDrop);
BeginUpdate();
foreach (string s in ss)
{
Items.Add(s);
}
EndUpdate();
//add your own Event Handler
XDragDrop(this, e);
}
void Xshow_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
else e.Effect = DragDropEffects.None;
}
void Xshow_ColumnClick(object sender, ColumnClickEventArgs e)
{
if (Items.Count <= 1) return;
SortType st = ListViewItemSorter as SortType;
if (st == null) ListViewItemSorter = new SortType(e.Column);
else
{
st.Descending = !st.Descending; st.SubcolIdx = e.Column;
}
Sort();
}
}
class Xshow : ListView
{
public event EventHandler<DragEventArgs> XDragDrop;
public Xshow()
: base()
{
base.AllowDrop = true;
base.View = View.Details;
base.FullRowSelect = true;
base.ColumnClick += new ColumnClickEventHandler(Xshow_ColumnClick);
base.DragEnter += new DragEventHandler(Xshow_DragEnter);
base.DragDrop += new DragEventHandler(Xshow_DragDrop);
Columns.Add("Path",500);
}
class SortType : IComparer
{
int _subcolIdx;
bool _descending;
public int SubcolIdx
{
get { return _subcolIdx; }
set { _subcolIdx = value; }
}
public bool Descending
{
get { return _descending; }
set { _descending = value; }
}
public SortType(int subcolIdx)
{
_subcolIdx = subcolIdx;
_descending = false;
}
public int Compare(object a, object b)
{
ListViewItem x, y;
if (_descending) { x = (ListViewItem)b; y = (ListViewItem)a; }
else { x = (ListViewItem)a; y = (ListViewItem)b; }
//SubItems[0] == item in first row, SubItems[1]=first subitem
return String.Compare(x.SubItems[_subcolIdx].Text, y.SubItems[_subcolIdx].Text);
}
}
void Xshow_DragDrop(object sender, DragEventArgs e)
{
string[] ss = (string[])e.Data.GetData(DataFormats.FileDrop);
BeginUpdate();
foreach (string s in ss)
{
Items.Add(s);
}
EndUpdate();
//add your own Event Handler
XDragDrop(this, e);
}
void Xshow_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
else e.Effect = DragDropEffects.None;
}
void Xshow_ColumnClick(object sender, ColumnClickEventArgs e)
{
if (Items.Count <= 1) return;
SortType st = ListViewItemSorter as SortType;
if (st == null) ListViewItemSorter = new SortType(e.Column);
else
{
st.Descending = !st.Descending; st.SubcolIdx = e.Column;
}
Sort();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询