|
|
|
ASP.Net C# รบกสนถามเกี่ยวกับ DropdownList หน่อยครับตอนเลือกข้อมูล |
|
|
|
|
|
|
|
พอเลือกข้อมูลใน Dropdown แล้ว เลือกจาก บนลงล่างได้ หรือเลือกแค่ 1 ครั้งได้ แต่เลือกจากล่างขึ้นบนแล้ว มันไม่ขึ้นโชว์อะไรเลยอะครับมันขึ้นเป็น หน้า เปล่าๆ ไม่ทราบว่าเป็นเพราะอะไร
code หน้ารวมทั้งหมด
import.aspx.cs
public partial class It_Admin_Import : System.Web.UI.Page
{
private string AD_Host = ConfigurationManager.AppSettings["AD_Host"].ToString();
private string AD_Port = ConfigurationManager.AppSettings["AD_Port"].ToString();
private string AD_UserObjectClass = ConfigurationManager.AppSettings["AD_UserObjectClass"].ToString();
private string AD_authenticationWith = ConfigurationManager.AppSettings["AD_authenticationWith"].ToString();
private string AD_Base = ConfigurationManager.AppSettings["AD_Base"].ToString();
private string AD_Username = ConfigurationManager.AppSettings["AD_Username"].ToString();
private string AD_Password = ConfigurationManager.AppSettings["AD_Password"].ToString();
//clsDatabase clsDB = new clsDatabase();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ddlSelect_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlSelect.SelectedValue == "01")
{
pnlImport.Visible = true;
pnlExport.Visible = false;
}
else if (ddlSelect.SelectedValue == "02")
{
pnlImport.Visible = false;
pnlExport.Visible = true;
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorAlert", "alert('กรุณาเลือกประเภทข้อมูลที่ต้องการโชว์');", true);
pnlImport.Visible = false;
pnlExport.Visible = false;
}
}
protected void ddlSearch_Type_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlSearch_Type.SelectedValue == "01")
{
gvStaff.Visible = true;
gvStudent.Visible = false;
BindData_gvStaff();
}
else if (ddlSearch_Type.SelectedValue == "02")
{
gvStaff.Visible = false;
gvStudent.Visible = true;
BindData_gvStudent();
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorAlert", "alert('กรุณาเลือกข้อมูลที่ต้องการ Export');", true);
gvStaff.Visible = false;
gvStudent.Visible = false;
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
// Search STAFF && STUDENT //
String strSQL;
DataTable dt;
if (txtSearch.Text.Length > 0)
{
if (ddlSearch_Type.SelectedValue == "01")
{
clsDatabase clsDB = new clsDatabase("0");
strSQL = "SELECT CITIZEN_ID,STF_FNAME,STF_LNAME,BIRTHDAY,TELEPHONE FROM UOC_STAFF WHERE CITIZEN_ID = '" + this.txtSearch.Text + "' ";
dt = clsDB.QueryDataTable(strSQL);
ViewState["ds"] = dt;
if (dt.Rows.Count > 0)
{
gvStaff.Visible = true;
gvStudent.Visible = false;
gvStaff.DataSource = dt;
gvStaff.DataBind();
}
}
else if (ddlSearch_Type.SelectedValue == "02")
{
clsDatabase clsDB = new clsDatabase("1");
strSQL = "SELECT STUDENTCODE,CITIZEN_ID,STD_FNAME,STD_LNAME,BIRTHDAY FROM UOC_STUDENT WHERE CITIZEN_ID = '" + this.txtSearch.Text + "' ";
dt = clsDB.QueryDataTable(strSQL);
ViewState["ds"] = dt;
if(dt.Rows.Count > 0)
{
gvStaff.Visible = false;
gvStudent.Visible = true;
gvStudent.DataSource = dt;
gvStudent.DataBind();
}
}
}
}
protected void BindData_gvStaff()
{
String strSQL;
clsDatabase clsDB = new clsDatabase("0");
strSQL = "SELECT CITIZEN_ID,STF_FNAME,STF_LNAME,BIRTHDAY,TELEPHONE FROM UOC_STAFF";
ViewState["ds"] = clsDB.QueryDataTable(strSQL);
gvStaff.DataSource = clsDB.QueryDataTable(strSQL);
gvStaff.DataBind();
}
protected void BindData_gvStudent()
{
String strSQL;
clsDatabase clsDB = new clsDatabase("1");
strSQL = "SELECT STUDENTCODE,CITIZEN_ID,STD_FNAME,STD_LNAME,BIRTHDAY FROM UOC_STUDENT";
ViewState["ds"] = clsDB.QueryDataTable(strSQL);
gvStudent.DataSource = clsDB.QueryDataTable(strSQL);
gvStudent.DataBind();
}
protected void gvStaff_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
String strSQL;
clsDatabase clsDB = new clsDatabase("0");
strSQL = "SELECT CITIZEN_ID,STF_FNAME,STF_LNAME,BIRTHDAY,TELEPHONE FROM UOC_STAFF";
ViewState["ds"] = clsDB.QueryDataTable(strSQL);
gvStaff.PageIndex = e.NewPageIndex;
gvStaff.DataSource = clsDB.QueryDataTable(strSQL);
gvStaff.DataBind();
}
protected void gvStudent_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
String strSQL;
clsDatabase clsDB = new clsDatabase("1");
strSQL = "SELECT STUDENTCODE,CITIZEN_ID,STD_FNAME,STD_LNAME,BIRTHDAY FROM UOC_STUDENT";
ViewState["ds"] = clsDB.QueryDataTable(strSQL);
gvStudent.PageIndex = e.NewPageIndex;
gvStudent.DataSource = clsDB.QueryDataTable(strSQL);
gvStudent.DataBind();
}
protected void btnExport_Click(object sender, EventArgs e)
{
if (ddlSearch_Type.SelectedValue == "01")
{
gvStaff.DataBind();
string filename = "Staff.xls";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
DataGrid dgGrid = new DataGrid();
dgGrid.DataSource = ViewState["ds"];
dgGrid.DataBind();
//Get the HTML for the control.
dgGrid.RenderControl(hw);
//Write the HTML back to the browser.
//Response.ContentType = application/vnd.ms-excel;
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
this.EnableViewState = false;
Response.Write(tw.ToString());
Response.End();
}
else if (ddlSearch_Type.SelectedValue == "02")
{
gvStudent.DataBind();
string filename = "Student.xls";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
DataGrid dgGrid = new DataGrid();
dgGrid.DataSource = ViewState["ds"];
dgGrid.DataBind();
//Get the HTML for the control.
dgGrid.RenderControl(hw);
//Write the HTML back to the browser.
//Response.ContentType = application/vnd.ms-excel;
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
this.EnableViewState = false;
Response.Write(tw.ToString());
Response.End();
}
else
{
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), C#, VS 2010 (.NET 4.x)
|
|
|
|
|
|
Date :
2013-09-15 11:46:01 |
By :
offonepoint |
View :
754 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
การ Debug ช่วยได้ครับ
|
|
|
|
|
Date :
2013-09-16 09:25:19 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|