?? systemtools.cs
字號:
?using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/// SystemTools 的摘要說明
/// </summary>
public class SystemTools
{
public SystemTools()
{
///
}
/// <summary>
/// 將DataReader轉(zhuǎn)為DataTable
/// </summary>
/// <param name="DataReader">DataReader</param>
public static DataTable ConvertDataReaderToDataTable(SqlDataReader dataReader)
{
///定義DataTable
DataTable datatable = new DataTable();
try
{ ///動(dòng)態(tài)添加表的數(shù)據(jù)列
for(int i = 0; i < dataReader.FieldCount; i++)
{
DataColumn myDataColumn = new DataColumn();
myDataColumn.DataType = dataReader.GetFieldType(i);
myDataColumn.ColumnName = dataReader.GetName(i);
datatable.Columns.Add(myDataColumn);
}
///添加表的數(shù)據(jù)
while(dataReader.Read())
{
DataRow myDataRow = datatable.NewRow();
for(int i = 0; i < dataReader.FieldCount; i++)
{
myDataRow[i] = dataReader[i].ToString();
}
datatable.Rows.Add(myDataRow);
myDataRow = null;
}
///關(guān)閉數(shù)據(jù)讀取器
dataReader.Close();
return datatable;
}
catch(Exception ex)
{
///拋出類型轉(zhuǎn)換錯(cuò)誤
throw new Exception(ex.Message,ex);
}
}
public static void SetListBoxItem(ListBox listBox,string sItemValue)
{
int index = 0;
foreach(ListItem item in listBox.Items)
{
///判斷值是否相等,并且設(shè)置控件的SelectedIndex
if(item.Value.ToLower() == sItemValue.ToLower())
{
listBox.SelectedIndex = index;
break;
}
index++;
}
}
public static void SetListBoxItem(DropDownList listBox,string sItemValue)
{
int index = 0;
foreach(ListItem item in listBox.Items)
{
///判斷值是否相等,并且設(shè)置控件的SelectedIndex
if(item.Value.ToLower() == sItemValue.ToLower())
{
listBox.SelectedIndex = index;
break;
}
index++;
}
}
public static void SetListBoxItem(ListBox listBox,string sItemValue,bool IsBool)
{
int index = 0;
if(IsBool == true)
{
sItemValue = sItemValue.ToLower() == "true" ? "1" : "0";
}
foreach(ListItem item in listBox.Items)
{
///判斷值是否相等,并且設(shè)置控件的SelectedIndex
if(item.Value.ToLower() == sItemValue.ToLower())
{
listBox.SelectedIndex = index;
break;
}
index++;
}
}
public static void SetListBoxItem(DropDownList listBox,string sItemValue,bool IsBool)
{
int index = 0;
if(IsBool == true)
{
sItemValue = sItemValue.ToLower() == "true" ? "1" : "0";
}
foreach(ListItem item in listBox.Items)
{
///判斷值是否相等,并且設(shè)置控件的SelectedIndex
if(item.Value.ToLower() == sItemValue.ToLower())
{
listBox.SelectedIndex = index;
break;
}
index++;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -