如何访问网格视图下的下拉列表? [英] how to acces the drop down list which under Grid view ?

查看:111
本文介绍了如何访问网格视图下的下拉列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi开发人员,
我的问题是如何访问网格视图下的下拉列表?

例如:每当我选择一个班级时,都应参加该班级的所有学生,例如:

hi developers,
my problem is how to access the dropdownlist which is under Grid view?

example: when ever i select a class all students who are in that class should be come, like:

name     section<br />
stephen     A
Roy         B
Nani        A
Thiru       C



就像我必须显示的一样,这里是下拉列表.

我曾经喜欢下面的代码,



like wise i have to display, here section is drop down list .

i used like following code,

string sections = String.Empty;        
DataTable dt = new DataTable();        
dt.Columns.Add("sectionid");        
foreach (GridViewRow row in gvsectionchange.Rows)        
{
    sections = ((DropDownList)row.FindControl("ddlChangeSection")).SelectedItem.Value;
    DataRow dr = dt.NewRow();        
    dr["sectionid"] = sections;        
    dt.Rows.Add(dr);
}



这是一个问题,下拉列表正在填充,但没有显示确切的部分.

谢谢你,
最好的问候,
Thiru



here is some problem,drop down is filling but not displaying the exact sections.

Thank u,
Best Regards,
Thiru

推荐答案

好像您已从此处复制了一段代码. [ ^ ]并尝试了一下.您尝试的内容与该链接示例中的操作有所不同.

您无需制作数据表即可填充下拉列表并在dropdownlist中显示相应的部分.

使用模板字段,在ItemTemplate中的填充/设置"下拉列表值中.
做到这一点的方法之一可以是:
Looks like you have copied piece of code from here.[^]and just tried it. What you are trying is different than what''s being done in the sample of that link.

You don''t need to make the datatable in order to fill the dropdown and display the appropriate sections in dropdownlist.

Use a template field, where in ItemTemplate fill/set Dropdown values.
One of the ways to do it can be:
<asp:TemplateField HeaderText="User Name">
  <ItemTemplate>
    <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true" DataSourceID="SqlDataSource1" DataValueField=sectionname AutoPostBack="True" SelectedValue='<%# Bind("sectionname")%>'>
       <asp:ListItem Value="">Select an Item</asp:ListItem>
    </asp:DropDownList>
  </ItemTemplate>
</asp:TemplateField> 



如果仍然需要,只需google,如何将下拉菜单添加到gridview,您将发现很多关于此的文章. :thumbsup:



If still needed, just google, how to add dropdown to gridview, and you will find lots of writeup on that. :thumbsup:


这篇关于如何访问网格视图下的下拉列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆