梦之翼飞翔

软件天堂

ListView 多行选择

<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  int id = -1;
  protected void Page_Load(object sender, EventArgs e)
  {
    Int32.TryParse(xx.Value, out id);
    Bind();
  }   
  protected void Bind()
  {
    ListView1.SelectedIndex = id;
    System.Data.DataTable dataTable1 = new System.Data.DataTable("BlogUser");
    System.Data.DataRow dr;
    dataTable1.Columns.Add(new System.Data.DataColumn("UserId", typeof(System.Int32)));
    dataTable1.Columns.Add(new System.Data.DataColumn("UserName", typeof(System.String)));
    dataTable1.PrimaryKey = new System.Data.DataColumn[] { dataTable1.Columns["UserId"] };
    for (int i = 0; i < 8; i++)
    {
      dr = dataTable1.NewRow();
      dr[0] = i;
      dr[1] = "用户姓名【孟子E章】测试" + i.ToString();
      dataTable1.Rows.Add(dr);
    }
    ListView1.DataSource = dataTable1.DefaultView;
    ListView1.DataBind();

  }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
  <form id="form1" runat="server">
  <asp:HiddenField ID="xx" runat="server" Value="-1" />
  <asp:ListView ID="ListView1" runat="server">
    <ItemTemplate>
      <div onclick="document.getElementById('<%=xx.ClientID %>').value='<%#Container.DataItemIndex %>';document.getElementById('<%=form1.ClientID %>').submit();">
        <%#Eval("UserName")%></div>
    </ItemTemplate>
    <SelectedItemTemplate>
      <div style="background: red">
        <%#Eval("UserName")%></div>
    </SelectedItemTemplate>
  </asp:ListView>
  </form>
</body>
</html>

阅读更多
个人分类: VB.NET Asp.Net
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭