asp.net使用WCF实体框架Linq [英] asp.net using WCF Entity Framework Linq
问题描述
你好,
i使用WCF asp.net使用实体框架linq绑定下拉列表
但我收到错误连接已关闭。
我的代码:
public void FillClientNameDropDown(long clientid,DropDownList ddl)
{
使用(ListClientServiceReference.ClientListClient client = new ListClientServiceReference.ClientListClient())
{
ddl.DataSource = client.GetName( clientid);
ddl.DataValueField =ClientId;
ddl.DataTextField =姓名;
ddl.DataBind();
ddl.Items.Insert(0,new ListItem( - Select Product Type-, - 1)); < br $>
}
}
请告诉我如何解决问题。 />
i搜索谷歌,但我没有得到任何答案。
要在视图中使用下拉列表,您需要填充SelectList对象。示例:
// 在我的控制器中,我创建了db.Tags中所有项目的列表,其值为Id,text为Name,选中的值为tagstologos.TagId。
ViewBag.TagId = new SelectList(db.Tags, Id, 名称,tagstologos.TagId);
// 在我的视图中,我使用HTML帮助器创建下拉列表。
@ Html.DropDownList( TagId,字符串跨度> .Empty)
Hello ,
i binding the dropdownlist using WCF asp.net using entity framework linq
but i am getting error connection closed.
My code:
public void FillClientNameDropDown(long clientid, DropDownList ddl)
{
using (ListClientServiceReference.ClientListClient client = new ListClientServiceReference.ClientListClient())
{
ddl.DataSource = client.GetName(clientid);
ddl.DataValueField = "ClientId";
ddl.DataTextField = "Name";
ddl.DataBind();
ddl.Items.Insert(0, new ListItem("-Select Product Type-", "-1"));
}
}
plz tell me how to slove.
i search on the google but i am not getting any answer.
To use a dropdown list in your view you need to populate a SelectList object. Example:
//In my controller I create a list of all items in db.Tags, with value is Id, text is Name and selected value is tagstologos.TagId. ViewBag.TagId = new SelectList(db.Tags, "Id", "Name", tagstologos.TagId); //In my view I create the dropdownlist with a HTML helper. @Html.DropDownList("TagId", String.Empty)
这篇关于asp.net使用WCF实体框架Linq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!