Pass a value to a datagrid cell on Gridview on SelectIndexChanged
Please Guys, I want to pass the value I read from my select statement to a
row cell when I select a value from a dropdownlist. I want the selected
value from my dropdownlist to only assign the value from my select
statement to that cell on that particular row. It does not seem to be
working for me. Please can someone assist. Here is my code thanks.
protected void treatmentNameList_SelectedIndexChanged(object sender,
EventArgs e) {
try
{
DataSet ds = new DataSet();
DropDownList treatmentName = (DropDownList)sender;
String sqlConStr =
ConfigurationManager.ConnectionStrings["AppConnectionString"].ToString();
SqlConnection con = new SqlConnection(sqlConStr);
con.Open();
SqlCommand cmd = new SqlCommand("SELECT tariff.Cost FROM
Tariffs tariff, "
+ "TreatmentCost treatCost WHERE (treatCost.TariffID =
tariff.ID) AND (treatCost.TariffID = tariff.ID) AND
(treatCost.ID=@treatCostID)", con);
cmd.Parameters.AddWithValue("@treatCostID",
treatmentName.SelectedValue.ToString());
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
con.Close();
// I want to assign the result of my select statement to a cell in gridview
}
catch (Exception err)
{
lblResults.Text = "Error Fetching Data." + err.Message;
}
}
Thanks.
No comments:
Post a Comment