|
|
|
ถามเกี่ยวกับ dropdownlist 2 ตัว ต้องการเลือกให้เปลี่ยนตามข้อมูลที่มีแต่มีerrorครับ (query จาก database) |
|
|
|
|
|
|
|
Code เขียนอะไรบ้างครับ
|
|
|
|
|
Date :
2011-08-29 21:31:53 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
querybindingใส่ datatable แยกกันครับเพื่อจะได้where and date=วันที่เลือกจากdropdown
โดยแยกใส่แต่ละdatable
Code (C#)
Dbcon oCon = new Dbcon();
oCon.OpenConnection();
string strSql = "SELECT DISTINCT CONVERT(VARCHAR(10),pDate,103) AS pDate,pTime " +
"FROM pRound T1 WHERE T1.pID=@ppID ";
SqlCommand oCommandSql = new SqlCommand(strSql, oCon.DbConnect);
oCommandSql.Parameters.Add("@ppID", SqlDbType.Int).Value = hdnpID.Value;
SqlDataAdapter oAdapterSql = new SqlDataAdapter(oCommandSql);
DataTable dtdropdown1 = new DataTable();
oAdapterSql.Fill(dtdropdown1);
oAdapterSql = null;
//-----------------------------------------------------------------------------------------------------------------------------
string sql = "SELECT DISTINCT CONVERT(VARCHAR(10),pDate,103) AS pDate,pTime " +
"FROM pRound T1 WHERE T1.pID=@ppID and CONVERT(VARCHAR(10),pDate,103) = @ppDate";
SqlCommand oSqlCommand = new SqlCommand(sql, oCon.DbConnect);
oSqlCommand.Parameters.Add("@ppID", SqlDbType.Int).Value = hdnpID.Value;
oSqlCommand.Parameters.Add("@ppDate", SqlDbType.VarChar).Value = hdndd1.Value;
SqlDataAdapter osqlAdapter = new SqlDataAdapter(oSqlCommand);
DataTable dtdropdown2 = new DataTable();
osqlAdapter.Fill(dtdropdown2);
osqlAdapter = null;
oCon.Dispose();
DataTable dtDdl1 = dtdropdown1.DefaultView.ToTable("dtDdl1", true, "pDate");
DataTable dtDdl2 = dtdropdown2.DefaultView.ToTable("dtDdl2", true, "pTime");
ddl1.Items.Clear();
ddl1.DataSource = dtDdl1;
ddl1.DataTextField = "pDate";
ddl1.DataValueField = "pDate";
ddl1.DataBind();
ddl2.Items.Clear();
ddl2.DataSource = dtDdl2;
ddl2.DataTextField = "pTime";
ddl2.DataValueField = "pTime";
ddl2.DataBind();
ddl1.SelectedValue = hdnddl1.Value; //hidden field
ddl2.SelectedValue = hdnddl2.Value;
EX.
29/08/2011 ----> 11:00, 12:00, 13:00, 14:00, 15:00, 16:00
30/08/2011 ----> 12:00, 15:00, 16:00
ddl1 เลือก 29/08/2011 ddl2 จะมีข้อมูล 11:00, 12:00, 13:00, 14:00, 15:00, 16:00
ddl2 เลือก 30/08/2011 ddl2 จะมีข้อมูล 12:00, 15:00, 16:00
|
|
|
|
|
Date :
2011-08-29 23:07:55 |
By :
question |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|