Answer the question
In order to leave comments, you need to log in
Where exactly is it necessary to run the function with loading the list of categories from the database into the DetailsView, which is visible = false by default?
Such is the problem. There is a DetailsView as a "pop-up" that has a dropdownlist with categories.
Made the following function
p.s. ddl_text is the ddl that is in the DetailsView, and ddl_Category is on the page itself, and is visible on load
private void loadCategoryList()
{
DropDownList ddl_Text = (DropDownList)dvPurchase.FindControl("ddl_Text");
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DB_Name"].ConnectionString))
{
SqlCommand cmd = new SqlCommand("usp_Category_Select", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection.Open();
cmd.Parameters.Add("@UserID", SqlDbType.Int).Value = Session["UserID"];
ddl_Text.DataSource = cmd.ExecuteReader();
ddl_Text.DataTextField = "Category";
ddl_Text.DataValueField = "CategoryID";
ddl_Text.DataBind();
cmd.Connection.Close();
}
ddl_Category.DataSource = ddl_Text.Items;
ddl_Category.DataBind();
}
Answer the question
In order to leave comments, you need to log in
Eh, I decided, but it seems to me - in a very dirty way. Or is this the very abyss that is not liked in asp.net because of the View States :)
protected void dvPurchase_DataBound(object sender, EventArgs e)
{
DropDownList ddl_Text = (DropDownList)dvPurchase.FindControl("ddl_Text");
if (dvPurchase.CurrentMode == DetailsViewMode.Insert)
{
loadCategoryList();
Label1.Text = "Insert";
}
if (dvPurchase.CurrentMode == DetailsViewMode.Edit)
{
loadCategoryList();
Label1.Text = "Edit";
}
if (dvPurchase.CurrentMode == DetailsViewMode.ReadOnly)
Label1.Text = "ReadOnly";
}
If you have solved your problem - congratulations. The problem of using WebForms remains. Today the technology is too heavy and opaque. Try to teach the site to understand both WebForms and MVC and slowly migrate there. on MVC, requests and markup generation are more transparent.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question