【1】
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="ID" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
<asp:ListItem Text="选项1" Value="1001" Selected="False" ></asp:ListItem>
<asp:ListItem Text="选项2" Value="1002" Selected="False"></asp:ListItem>
<asp:ListItem Text="选项3" Value="1003" Selected="False"></asp:ListItem>
<asp:ListItem Text="选项4" Value="0" Selected="False"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ShowHeader="true" DataField="ID" HeaderText="ID" />
<asp:BoundField ShowHeader="true" DataField="name" HeaderText="姓名" />
</Columns>
</asp:GridView>
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList DropDownList1 = sender as DropDownList;
int index = (DropDownList1.NamingContainer as GridViewRow).RowIndex;
string id = GridView1.DataKeys[index].Value.ToString();
/////////////////////////////////////////////////////////////////////////////////////////
4 DropDownList drp = sender as DropDownList; // 触发事件的 DropDownList
5 GridViewRow row = drp.NamingContainer as GridViewRow; // GridView 当前行 即时在dropdownlist所在容器里 就是行的信息
6 row.Style.Add(HtmlTextWriterStyle.BackgroundColor, drp.SelectedValue);
7 Response.Write(row.RowIndex+1);//获取dropdownlist中选定行的行号.
8 //Response.Write(String.Format("选中第 {0} 行", row.RowIndex + 1));
9 DropDownList ddlClass = (DropDownList)sender;
10 string ClassID = ddlClass.SelectedValue.ToString();//获取Dropdownlist中选定值
}
【2】
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" ABCD='<%# Eval("primary_field") %>'>
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList dr = sender as DropDownList;
string keyValue=dr.Attributes["ABCD"];
//根据keyValue进行处理。
}
分享到:
相关推荐
GridView控件中DropDownList控件的绑定
gridview与dropdownlist组合,用的挺好,在gridview中实现数据交互.
1:在Gridview中无须编写后台代码,直接实现增除删改 2:在Gridview中添加新记录 3:在Gridview中实现编辑和更新操作 4:在Gridview中实现一次性更新所有记录 5:在Gridview中固定表头的实现 6:在...
1:在Gridview中无须编写后台代码,直接实现增除删改 2:在Gridview中添加新记录 3:在Gridview中实现编辑和更新操作 4:在Gridview中实现一次性更新所有记录 5:在Gridview中固定表头的实现 6:在...
1:在Gridview中无须编写后台代码,直接实现增除删改 2:在Gridview中添加新记录 3:在Gridview中实现编辑和更新操作 4:在Gridview中实现一次性更新所有记录 5:在Gridview中固定表头的实现 6:在...
7.鼠标移到GridView某一行时改变该行的背景色方法二: 8.GridView实现删除时弹出确认对话框: 9.GridView实现自动编号: 10.GridView实现自定义时间货币等字符串格式: 11.GridView实现自定义时间货币等字符串格式...
gridview中将dropdownlist中的Value赋给lebal
ASP.NET中dropdownlist和GridView控件的用法,简单易学,一看就懂.
GridView和下拉菜单DropDownList结合,在gridview中使用dropdownlist
ddl = (DropDownList)GridView1.Rows[i].FindControl("depList"); ddl.SelectedValue = ds.Tables[0].Rows[i]["DepId"].ToString(); ddl = (DropDownList)GridView1.Rows[i].FindControl("roleList"); ddl....
DropDownList结合GridView的实例,DropDownList如何赋值,或是在GridView编辑时,DropDownList是如何取到原值。 本影片Size:6284KB;长度:0:13:59
获取gridview中数据及添加dropdownlist,在DataGridView中添加下拉菜单,实现DropDownlist功能
实现GridView动态列,以及使用模板添加DropDownList,在点击编辑后整行的DropDownList显示出来。
适合初学者学
7.鼠标移到GridView某一行时改变该行的背景色方法二: 14 8.GridView实现删除时弹出确认对话框: 15 9.GridView实现自动编号: 15 10.GridView实现自定义时间货币等字符串格式: 17 前台代码: 18 11.GridView实现用...
7.鼠标移到GridView某一行时改变该行的背景色方法二 8.GridView实现删除时弹出确认对话框 9.GridView实现自动编号 10.GridView实现自定义时间货币等字符串格式 11.GridView实现用“...”代替超长字符串
GridView空间中的各种使用方法,包括GridView无代码分页排序 GridView选中,编辑,取消,删除 GridView正反双向排序 GridView和下拉菜单DropDownList结合 GridView和CheckBox结合 鼠标移到GridView某一行时改变该行...
鼠标移到GridView某一行时改变该行的背景色方法二 GridView实现删除时弹出确认对话框 GridView实现自动编号 GridView实现自定义时间货币等字符串格式 GridView实现用“...”代替超长字符串 GridView一般换行与强制...
获取GridView中Checkbox的值