1
我有一個DropDownList
從數據庫中填充。當我在索引1上選擇一條記錄時,它會得到正確的結果,但是當我選擇第二個索引時,它會出現相同的索引。它看起來像DropDownList
默認顯示第一個索引。我如何在DropDownList
中選擇變更索引? 因此,如果將選擇索引3,結果必須來自索引3. 我試過DropDownList.SelectedItem
,DropDownList.SelectedValue
, DropDownList.SelectedIndex
,DropDownList.Text
但沒有效果似乎在那裏。在Page_Load中索引在下拉菜單中沒有變化C#Asp.Net
public void load_Individual()
{
if (IsPostBack == false)
{
SqlDataAdapter sdaIndividual = new SqlDataAdapter("select * from tbl_trip", _connectionString);
DataTable dtIndividual = new DataTable();
sdaIndividual.Fill(dtIndividual);
if (dtIndividual.Rows.Count > 0)
{
ddl_Individual.DataTextField = "TruckNo";
ddl_Individual.DataValueField = "TruckNo";
ddl_Individual.DataSource = dtIndividual;
ddl_Individual.DataBind();
}
}
}
的DropDownList
DropDownList的加載對於選擇價值觀
if (ddl_Individual.Text != string.Empty)
{
ddl_Individual.ClearSelection();
adp = new SqlDataAdapter(@"Select * , '' as c1, '' as c2, 0 as c3 , 0 as c4 , 0 as c5 , 0 as c6, 0 as c7 , 0 as c8 from tbl_Trip
where TruckNo='" + ddl_Individual.SelectedValue + "'", _connectionString);
adp.Fill(Dt);
Session["mydata"] = Dt;
Response.Redirect("LoadReport.aspx");
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(),"alertMessage","aler('select valid value')", true);
}
我試過這個,但是沒有效果。請分享一個備用解決方案請 –
其實我的應用程序是一個小應用程序,不需要使用Sql注入。那麼你想分享另一個替代品嗎? –