I have one Repeater control. Inside the repeater control I have drop down list,Text Box. Then I have Upload functionality on upload it fills Text Box but it is not setting the value in drop down list. Please let me know how to bind Data Table value to drop
down list inside the repeater control. Please provide me a code.
if (e.Row.RowType == DataControlRowType.DataRow)
{
// to fill all the region in the edittemplate of Region field in the gridview
DropDownList ddl = (DropDownList)e.Item.FindControl("DropDownList1");
fc.FillDropCombos(ddl, "select ROName as name, RoCode as id from ROmast", "select" , connCBR);
}
// FillDropCombos function
public void FillDropCombos(DropDownList ddlCombo, string SQLString, string InitialValue, string con)
{
DataSet ds = new DataSet();
try
{
if (SQLString != "")
{
ListItem lst = new ListItem(InitialValue, "");
ds = getDataSet(SQLString, con);
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
ddlCombo.DataSource = ds;
ddlCombo.DataTextField = "name";
ddlCombo.DataValueField = "id";
ddlCombo.DataBind();
}
}
if (InitialValue != "No")
{
ddlCombo.Items.Insert(0, lst);
}
foreach (DataRow theRow in ds.Tables[0].Rows)
{
if (Convert.ToBoolean(theRow["def"]) == true)
{
ddlCombo.SelectedValue = theRow["Id"].ToString();
}
}
}
}
catch (Exception ex)
{
errMessage = ex.Message;
}
}
public DataSet getDataSet(string SQLString, string con)
{
using (connection = new SqlConnection(con))
{
try
{
connection.Open();
Com = new SqlCommand(SQLString, connection);
da = new SqlDataAdapter(Com);
ds = new DataSet();
da.Fill(ds);
connection.Close();
}
catch (Exception e)
{
errMessage = e.ToString();
}
return ds;
}
}
Mark this post as answer if it helps you!!!
Regards
Rima Gandhi.
Software Developer.
Marked as answer by santoshhegde on Jan 30, 2013 06:23 AM
santoshhegde
Member
10 Points
25 Posts
Fill data is the drop down list inside repeater control on upload
Jan 29, 2013 08:22 AM|LINK
Hi,
I have one Repeater control. Inside the repeater control I have drop down list,Text Box. Then I have Upload functionality on upload it fills Text Box but it is not setting the value in drop down list. Please let me know how to bind Data Table value to drop down list inside the repeater control. Please provide me a code.
rimagandhi
Participant
1589 Points
512 Posts
Re: Fill data is the drop down list inside repeater control on upload
Jan 29, 2013 08:30 AM|LINK
On ItemDatabound control event write below code:
if (e.Row.RowType == DataControlRowType.DataRow)
{
// to fill all the region in the edittemplate of Region field in the gridview
DropDownList ddl = (DropDownList)e.Item.FindControl("DropDownList1");
fc.FillDropCombos(ddl, "select ROName as name, RoCode as id from ROmast", "select" , connCBR);
}
// FillDropCombos function
public void FillDropCombos(DropDownList ddlCombo, string SQLString, string InitialValue, string con)
{
DataSet ds = new DataSet();
try
{
if (SQLString != "")
{
ListItem lst = new ListItem(InitialValue, "");
ds = getDataSet(SQLString, con);
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
ddlCombo.DataSource = ds;
ddlCombo.DataTextField = "name";
ddlCombo.DataValueField = "id";
ddlCombo.DataBind();
}
}
if (InitialValue != "No")
{
ddlCombo.Items.Insert(0, lst);
}
foreach (DataRow theRow in ds.Tables[0].Rows)
{
if (Convert.ToBoolean(theRow["def"]) == true)
{
ddlCombo.SelectedValue = theRow["Id"].ToString();
}
}
}
}
catch (Exception ex)
{
errMessage = ex.Message;
}
}
public DataSet getDataSet(string SQLString, string con)
{
using (connection = new SqlConnection(con))
{
try
{
connection.Open();
Com = new SqlCommand(SQLString, connection);
da = new SqlDataAdapter(Com);
ds = new DataSet();
da.Fill(ds);
connection.Close();
}
catch (Exception e)
{
errMessage = e.ToString();
}
return ds;
}
}
Regards
Rima Gandhi.
Software Developer.