分配Gridview DropDownList值

时间:2016-06-28 13:59:40

标签: c# sql asp.net gridview

我需要DropDownList ddlReceipt来显示数据库中的值。我目前的代码如下。

我觉得我的代码在ddlReceipt.SelectedValue =“toa_receipt”上是错误的;但我不确定。

foreach (GridViewRow row in gvCreditCards.Rows)
{
    DropDownList ddlReceipt = row.FindControl("ddlReceipt") as DropDownList;
    string id = row.Cells[0].Text;
    SqlConnection con2 = new SqlConnection(conStringTOA);
    SqlDataAdapter sda2 = new SqlDataAdapter();
    SqlCommand cmd2 = new SqlCommand("SELECT toa_receipt FROM toa_CreditCardStatement WHERE id = '" + id + "'");
    cmd2.Connection = con2;
    con2.Open();
    ddlReceipt.SelectedValue = "toa_receipt";
    con2.Close();
}

1 个答案:

答案 0 :(得分:1)

你遗漏了很多代码。您必须从数据库中读取数据(这就是您创建formatOutput)的原因。

SqlCommand