I had Repeater which bind method this method retrieve data from data base by stored procedure when Model_Id pass to this method it retrieve data also user can repeat repeater more than once when user select DDL more than once.I did the code and I add all Model_Ids which user select from DDL in array list but error appear
Cannot convert array list to string value:
protected void Add_Click(object sender, ImageClickEventArgs e)
{
ArrayList Array = new ArrayList();
Array.Add(DDLModel.SelectedValue);
DLHome.DataSource = Cls.GetModelName(Array);
DLHome.DataBind();
}
public DataTable GetModelName(string Model_Id)
{
using (SqlConnection conn = Connection.GetConnection())
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetComparisonModel";
SqlParameter ParentID_Param = cmd.Parameters.Add("@Model_Id", SqlDbType.Int);
ParentID_Param.Value = Model_Id;
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(dt);
return dt;
}
}
Surely you are getting a compiler error if this is you exact code?
GetModelNametakes a string as the parameter and you are passing in typeArrayList.If you want to convert your array of ID’s to string just have an extension method of ArrayList which iterates over each item and returns the string value e.g.
Looking at your code, the
ArrayListusage appears negligiable as you can simply passSelectedValuestraight into the Bind method.