2011年8月14日 星期日

[.NET] C# 常用function整理(一) 載入資料至RadioButtonList

C#.NET 範例程式
從DB讀取 Item 載入 RadioButtonList 用




#region LoadRadioButtonList
///

/// 載入資料至RadioButtonList
///

///
///
protected RadioButtonList LoadRadioButtonList(RadioButtonList RbtnList, string FieldID)
{

RbtnList.Items.Clear();
string sSQL = "SELECT ItemID, ItemName FROM ItemTable where FieldID='" + FieldID + "'";
DataTable dt = this.DBConn.GeneralSqlCmd.ExecuteToDataTable(sSQL);
//Conn.Dispose();

for (int i = 0; i < dt.Rows.Count; i++)
{
RbtnList.Items.Add(new ListItem(dt.Rows[i]["ItemName"].ToString(), dt.Rows[i]["ItemID"].ToString()));
}
RbtnList.Dispose();

this.DBConn.Dispose(); this.DBConn = null;

return RbtnList;
}
#endregion

沒有留言:

張貼留言