public List<gridview> getrecord(gridview record)
{
List<gridview> gridview1 = new List<gridview>();
using (SqlConnection conn = new SqlConnection(@"Data Source=AGIDNET114\sqlexpress;Initial Catalog=Telerik;User ID=sa;Password=agiline123"))
{
SqlCommand cmd = new SqlCommand("getdemotable", conn);
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
conn.Close();
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
var model = new gridview();
model.Address = ds.Tables[0].Rows[i]["Address"].ToString();
model.Name = ds.Tables[0].Rows[i]["Name"].ToString();
model.PhoneNo = ds.Tables[0].Rows[i]["PhoneNo"].ToString();
model.Id = ds.Tables[0].Rows[i]["Id"].ToString();
gridview1.Add(model);
}
}
return gridview1;
}
遵循這段代碼在模型類,然後添加代碼視圖
public ActionResult getdata(gridview data)
{
var x = data.getrecord(data);
return View(x);
}
參考http://stackoverflow.com/questions/5438798/how-to-創建一個單選列表框顯示選擇使用剃鬚刀 – Cris
感謝您的Quicky Reply.But我需要從SQL數據庫中檢索數據到組合框。 – Ramalingam
發表你試過了什麼 – Cris