大家好,又见面了,我是你们的朋友全栈君。
aspx页面部分代码:
<asp:DataGrid id=”DataGrid1″ runat=”server” AutoGenerateColumns=”False”> <Columns> <asp:BoundColumn DataField=”txtId”></asp:BoundColumn> <asp:BoundColumn DataField=”txtName”></asp:BoundColumn> <asp:TemplateColumn> <ItemTemplate> <asp:ImageButton id=”btnItem” runat=”server” CommandName=”LookDetail”></asp:ImageButton> <asp:DropDownList id=”ddl” runat=”server” AutoPostBack=”True”> <asp:ListItem Value=”asdf”>asdf</asp:ListItem> <asp:ListItem Value=”asdfasdf”>asdfasdf</asp:ListItem> <asp:ListItem Value=”wrwwewewee”>wrwwewewee</asp:ListItem> </asp:DropDownList> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid>
cs部分代码:
cs部分代码:
/// <summary> /// 设计器支持所需的方法 – 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.DataGrid1.ItemCreated = new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemCreated); this.DataGrid1.ItemCommand = new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_ItemCommand); this.Load = new System.EventHandler(this.Page_Load);
}
private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { if(e.CommandName==”LookDetail”) { Response.Write(“clicked item—>” e.Item.Cells[0].Text); } }
private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { DropDownList ddl=(DropDownList)e.Item.FindControl(“ddl”); if(ddl!=null) { ddl.SelectedIndexChanged =new EventHandler(ddl_SelectedIndexChanged); } }
private void ddl_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddl=(DropDownList)sender; Response.Write(“当前选择的:” ddl.SelectedValue);
TableCell cell=(TableCell)ddl.Parent; DataGridItem item=(DataGridItem)cell.Parent; Response.Write(“当前行:” item.Cells[0].Text); }
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/194982.html原文链接:https://javaforall.cn