日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
實(shí)現(xiàn)ListBox多選并顯示數(shù)據(jù)的方法

本文向大家介紹C# ListBox多選,可能好多人還不了解C# ListBox多選,沒有關(guān)系,看完本文你肯定有不少收獲,希望本文能教會(huì)你更多東西。

專注于為中小企業(yè)提供成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)寧海免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了1000多家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

C#  ListBox多選并顯示數(shù)據(jù)似乎有些難,但是大家看了筆者實(shí)現(xiàn)此內(nèi)容的代碼已經(jīng)就不會(huì)覺得很難了。

 
 
 
  1. <%@ Page Language="C#" AutoEventWireup="true" Debug="true"%>  
  2. <%@import namespace="System.Data"%>  
  3. <%@import namespace="System.Data.SqlClient"%>  
  4.  
  5.  
  6.  
  7. "server">  
  8. "ckbEmployees" runat="server" RepeatLayout="table" RepeatDirection="vertical" RepeatColumns="3" CellPadding="9" CellSpacing="18" TextAlign="right" OnSelectedIndexChanged="subListChange" AutoPostBack="true" />  


  9.  
  10. "dgEmployee" runat="server" />  
  11.  
  12.  
  13.  
  14. "c#" runat="server">  
  15. private void Page_load(object sender,System.EventArgs e)  
  16. {  
  17. if(!IsPostBack)  
  18. {  
  19.    string strConnection ="server=.;uid=sa;pwd=sunix!;database=northwind";  
  20.    string strSQLforCheckBoxes = "select LastName ,EmployeeID from employees order by lastname";  
  21.    SqlConnection objConnection = new SqlConnection(strConnection);  
  22.    SqlCommand objCommand = new SqlCommand(strSQLforCheckBoxes,objConnection);  
  23.    objConnection.Open();  
  24.    ckbEmployees.DataSource = objCommand.ExecuteReader();  
  25.    ckbEmployees.DataTextField = "LastName";  
  26.    ckbEmployees.DataValueField = "EmployeeID";  
  27.    ckbEmployees.DataBind();  
  28.    objConnection.Close();  
  29. }  
  30. }  
  31. private void subListChange(object s,System.EventArgs e)  
  32. {  
  33. Response.Write("subListchange triggered
    ");  
  34. string strWhereClause="";  
  35. foreach (ListItem liThisOne in ckbEmployees.Items)  
  36. {  
  37.    if(liThisOne.Selected)  
  38.    {  
  39.     strWhereClause += "EmployeeID = " + liThisOne.Value + " OR ";  
  40.    }  
  41. }  
  42. Response.Write("strWhereClause=
    "+strWhereClause+"
    ");  
  43. if(strWhereClause.Length>0)  
  44. {  
  45.    dgEmployee.Visible = true;  
  46.    string str = strWhereClause.Substring(0,strWhereClause.Length - 3);  
  47.    strWhereClause = " where " + str;  
  48.    string strConnection = "server=.;uid=sa;pwd=sunix!;database=northwind";  
  49.    string strSQLforGrid = "select TitleOfCourtesy,firstName,lastName,country,region,city,notes from employees " + strWhereClause;  
  50.      //Response.Write(strSQLforGrid); sql語句之間的空格,否則出錯(cuò)  
  51.    SqlConnection objConnection = new SqlConnection(strConnection);  
  52.    SqlCommand objCommand = new SqlCommand(strSQLforGrid,objConnection);  
  53.    Response.Write("strSQLforGrid=
    "+strSQLforGrid+"
    ");  
  54.    objConnection.Open();  
  55.    dgEmployee.DataSource = objCommand.ExecuteReader();  
  56.    dgEmployee.DataBind();  
  57.    objConnection.Close();  
  58. }  
  59. else 
  60. {  
  61.    dgEmployee.Visible = false;  
  62. }  
  63. }  
  64.     

怎樣,筆者分享的C#  ListBox多選并顯示數(shù)據(jù)的代碼希望大家有用!


分享題目:實(shí)現(xiàn)ListBox多選并顯示數(shù)據(jù)的方法
URL標(biāo)題:http://www.dlmjj.cn/article/djpsoie.html