[英]How to show DropdownList in EditMode of GridView in ASP.Net C#?
I have a gridview1 and it has a normal field. 我有一个gridview1,它有一个正常的领域。 After clicking edit link, I want to show a
DropdownList
that reads from my Database. 单击编辑链接后,我想显示一个从数据库读取的
DropdownList
。 How can I achieve this? 我该如何实现?
this is my code for list template: 这是我的列表模板代码:
<asp:TemplateField HeaderText="Course Name">
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("CName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlECName" CssClass="auto-style16" Width="80px" runat="server" ></asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlCName" CssClass="auto-style16" Width="80px" runat="server" ></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
for adding values in ddl : 用于在ddl中添加值:
//This code for adding values in course name list in the edit mood
DropDownList ddlECName = ????? as DropDownList;
ddlECName.DataSource = GetData("SELECT * FROM TBCourse INNER JOIN TbCourseMajor ON TBCourse.CId = TbCourseMajor.CId AND TbCourseMajor.MNom='" + DLMNom.SelectedValue + "'");
ddlECName.DataTextField = "CName";
ddlECName.DataValueField = "CId";
ddlECName.DataBind();
//Add Default Item in the DropDownList
ddlECName.Items.Insert(0, new ListItem("----"));
The question is what should I write to define ddlECName ? 问题是我应该写什么来定义ddlECName? how to tell them that I mean the ddl that in edit mode of grid view?
如何告诉他们我的意思是在网格视图的编辑模式下的ddl?
The second question is where to write this in which function ? 第二个问题是在哪个函数中将此写在哪里? Ex: OnRowEditing...etc
例如:OnRowEditing ...等
I have confusion in dealing with grid view methods if you know a good explanation please give the url. 如果您知道很好的解释,请在提供URL的同时处理网格视图方法时感到困惑。 thank you
谢谢
It would go in your RowDataBound event. 它将进入您的RowDataBound事件。 So you will have to check the row state (edit) and bind the dropdown.
因此,您将必须检查行状态(编辑)并绑定下拉列表。
Please refer- Gridview row editing - dynamic binding to a DropDownList https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview_events(v=vs.110).aspx http://www.codeproject.com/Articles/36528/GridView-all-in-one 请参考-Gridview行编辑-动态绑定到DropDownList https://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.gridview_events(v=vs.110).aspx http:// www.codeproject.com/Articles/36528/GridView-all-in-one
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.