Yes, that seems to do the trick. Hovewer, I have one more question: How do I bind data to dropdownlist? I've tried
<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:
ddl = (DropDownList)FormView1.FindControl("ddlCategory");
ddl.DataSource = dReader;
ddl.DataTextField = "name";
ddl.DataValueField = "numberId";
Sorry to still bother, but any ideas?
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConn"].ToString());
string sSql = "SELECT numberId, name FROM Categories ORDER BY numberId DESC";
SqlCommand cmd = new SqlCommand(sSql, conn);
dReader = cmd.ExecuteReader();
This is dReader. All pasted coded is used at FormView1_DataBound event.
Oh well, I solved the problem by deleting all methods and adding data to dropdownlist by ObjectDataSource. You can lock this thread.