Yes, that seems to do the trick. Hovewer, I have one more question: How do I bind data to dropdownlist? I've tried
Code:
<asp:DropDownList ID="ddlCategory" runat="server" SelectedValue='<%# Bind("categoryId") %>'></asp:DropDownList>
which doesn't seem to work, as it says that "
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.".
The code used to populate dropdownlist:
Code:
DropDownList ddl;
ddl = (DropDownList)FormView1.FindControl("ddlCategory");
ddl.DataSource = dReader;
ddl.DataTextField = "name";
ddl.DataValueField = "numberId";
ddl.DataBind();
Sorry to still bother, but any ideas?
EDIT:
Code:
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConn"].ToString());
conn.Open();
string sSql = "SELECT numberId, name FROM Categories ORDER BY numberId DESC";
SqlCommand cmd = new SqlCommand(sSql, conn);
SqlDataReader dReader;
dReader = cmd.ExecuteReader();
This is dReader. All pasted coded is used at FormView1_DataBound event.
EDIT:
Oh well, I solved the problem by deleting all methods and adding data to dropdownlist by ObjectDataSource. You can lock this thread.