Greetings mates,
This is my first time here. Please take it easy on me.
I have been trying for the past two days to try to bind a data from the database to DropDownList in Repeater control but no luck so far.
I have the following:
- private void SetInitialRow2(string registerNumber, string bregisterNumber)
- {
- DataTable dt;
- if (ViewState["CurrentTable"] == null)
- {
- dt = new DataTable();
- DataRow dr = null;
-
- dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
- dt.Columns.Add(new DataColumn("PrevOnwerName", typeof(string)));
- dt.Columns.Add(new DataColumn("prevAddr", typeof(string)));
- dt.Columns.Add(new DataColumn("prevCity", typeof(string)));
- dt.Columns.Add(new DataColumn("PrevState", typeof(string)));
- dt.Columns.Add(new DataColumn("prevzip", typeof(string)));
-
-
- dr = dt.NewRow();
- dr["RowNumber"] = 1;
- dr["PrevOnwerName"] = string.Empty;
- dr["prevAddr"] = string.Empty;
- dr["prevCity"] = string.Empty;
- dr["PrevState"] = string.Empty;
- dr["prevzip"] = string.Empty;
- dt.Rows.Add(dr);
- }
- else
- {
- dt = (DataTable)ViewState["CurrentTable"];
- }
-
- ViewState["CurrentTable"] = dt;
- if (dt.Rows.Count > 0)
- {
-
- Repeater2.DataSource = dt;
- Repeater2.DataBind();
- }
- }
Then I have a stored procedure that pulls these records from the database.
The SP is called like this:
- private void getRecs(int pin)
- {
- SqlConnection conn = new SqlConnection(connStr);
- SqlCommand cmd = new SqlCommand("sp_AllRecs", conn);
- cmd.CommandType = CommandType.StoredProcedure;
- SqlParameter p1 = new SqlParameter("@pin", pin);
- cmd.Parameters.Add(p1);
- SqlDataAdapter sda = new SqlDataAdapter(cmd);
- DataTable dtPrevRecs = new DataTable();
- sda.Fill(dtPrevRecs);
- if (dtPrevRecs.Rows.Count > 0)
- {
- Repeater2.DataSource = dtPrevRecs;
- Repeater2.DataBind();
- ViewState["CurrentTable"] = dtPrevRecs;
- }
- }
I am also populating State DropDownList with the following:
- con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());
- string sSQL = "Select sID,sName from states ORDER By sName ASC";
-
-
- SqlCommand cmd3 = new SqlCommand(sSQL, con);
- con.Open();
- cstable = new DataTable();
- able.Load(cmd3.ExecuteReader());
Finally, my markup:
- <asp:DropDownList ID="ddlPrevState" cssClass="disabledcss" runat="server" AppendDataBoundItems="True">
- <asp:ListItem Value="" Selected="True"></asp:ListItem>
- </asp:DropDownList>
My question is when a user enters an account number, all records associated with that account populates the repeater form except the State dropdownlist.
Any ideas how to bind the data to the State dropdownlist?