日期:2014-05-17 浏览次数:20472 次
<asp:GridView ID="GridView1" runat="server" Font-Size="Medium" BackColor="Gray"
CellPadding="1" AllowSorting="True"
onrowcreated="GridView1_RowDataBound" >
<Columns>
<asp:TemplateField HeaderText="">
<ItemTemplate>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="選択">
<ItemTemplate>
<input ID="Checkbox1" type="checkbox" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="端末№">
<ItemTemplate>
<asp:DropDownList id="dlTerNo" runat="Server" autopostback="true" >
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
public partial class Page1 : System.Web.UI.Page
{
int m_nDataRow = 0;
CTblDUADDINF m_dbData = new CTblDUADDINF();
STCDUADDINF[] m_aDuaddinf = null;
struct STCDUADDINF
{
public string strMacAddress;
public string strCompanyCode;
public int nTerminalNo;
public int nAccessYMD;
public short nAccessHM;
};
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = GetDataSource();
GridView1.DataBind();
}
}
protected bool ReadDUADDINF()// 打開表
{
string strSql = string.Format("select {0}, {1}, {2}, {3}, {4} From {5}", CTblDUADDINF.S_MacAddress, CTblDUADDINF.S_CompanyCode, CTblDUADDINF.S_TerminalNo, CTblDUADDINF.S_AccessYMD, CTblDUADDINF.S_AccessHM, CTblDUADDINF.S_Tbl_Name);
m_dbData.Open(strSql, out m_nDataRow);
if (m_nDataRow > 0)
{
return true;
}
return false;
}
private DataTable GetDataSource()// 獲取數據
{
int nCnt = 0;
DataTable dt = new DataTable();
if (!IsPostBack)
{
if (ReadDUADDINF())
{
m_aDuaddinf = null;
m_aDuaddinf = new STCDUADDINF[m_nDataRow];
for (nCnt = 0; nCnt < m_nDataRow; nCnt++)
{
m_aDuaddinf[nCnt].strMacAddress = m_dbData.m_data.Tables[0].Rows[nCnt]["MacAddress"].ToString().Trim();
m_aDuaddinf[nCnt].strCompanyCode = m_dbData.m_data.Tables[0].Rows[nCnt]["CompanyCode"].ToString();
m_aDuaddinf[nCnt].nTerminalNo = (short)m_dbData.m_data.Tables[0].Rows[nCnt]["TerminalNo"];
m_aDuaddinf[nCnt]