[转]Raising An Event From CheckBox In A GridView (GridView中模板表的CheckBox的后台事件处理)
2009-08-13 11:49
447 查看
本文转自:http://www.dotnetspider.com/resources/30842-Raising-An-Event-From-CheckBox-In-A-GridView.aspx
原文如下:
Description:
Raising an event from a gridview check box or dropdown list.
In case of Button or Link Button then event raises and RowCommand.
Incase of raising event from a control like Checkbox or RadioButtonor DropDownList or etc Event Bubbling.
Design View:
<asp:GridView ID="GrdQuestions" AutoGenerateColumns="false" runat="server" Width="698px" >
<HeaderStyle HorizontalAlign="Left" CssClass="GridHeader" / >
<RowStyle CssClass="GridRowStyle" HorizontalAlign="Left" / >
<AlternatingRowStyle CssClass="GridAlternateRowStyle" / >
< Columns >
<asp:TemplateField HeaderText="Edit" >
<ItemStyle HorizontalAlign="Center" Width="50px" ></ItemStyle >
<ItemTemplate>
<asp:CheckBox id="chkStatus" AutoPostBack="True" Runat="server" OnCheckedChanged="chkStatus_Changed" ></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BatchPriority">
<HeaderStyle Wrap="False">< /HeaderStyle>
<ItemStyle Wrap="False">< /ItemStyle>
<ItemTemplate>
<asp:dropdownlist id="ddlBatchPriorty" runat="server" Width="92px" CssClass="text" ></asp:dropdownlist>
</ItemTemplate>
</asp:TemplateField>
<Columns>
</asp:GridView>
Code Behind:
public void chkStatus_Changed(object sender, System.EventArgs e)
{
//......When GridView Checkbox calls event, then it raises an event.
CheckBox chkbox = (CheckBox)(sender);
//......Sender is converted to checkbox and getting its GridView Row by using chkbox.Parent.Parent.
GridViewRow dg = (GridViewRow)(chkbox.Parent.Parent);
//......GridView Row to find the Control or Text of particular cell.
DropDownList ddl = (DropDownList)(dg.Cells[4].FindControl("ddlBatchPriorty"));
}
原文如下:
Description:
Raising an event from a gridview check box or dropdown list.
In case of Button or Link Button then event raises and RowCommand.
Incase of raising event from a control like Checkbox or RadioButtonor DropDownList or etc Event Bubbling.
Design View:
<asp:GridView ID="GrdQuestions" AutoGenerateColumns="false" runat="server" Width="698px" >
<HeaderStyle HorizontalAlign="Left" CssClass="GridHeader" / >
<RowStyle CssClass="GridRowStyle" HorizontalAlign="Left" / >
<AlternatingRowStyle CssClass="GridAlternateRowStyle" / >
< Columns >
<asp:TemplateField HeaderText="Edit" >
<ItemStyle HorizontalAlign="Center" Width="50px" ></ItemStyle >
<ItemTemplate>
<asp:CheckBox id="chkStatus" AutoPostBack="True" Runat="server" OnCheckedChanged="chkStatus_Changed" ></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BatchPriority">
<HeaderStyle Wrap="False">< /HeaderStyle>
<ItemStyle Wrap="False">< /ItemStyle>
<ItemTemplate>
<asp:dropdownlist id="ddlBatchPriorty" runat="server" Width="92px" CssClass="text" ></asp:dropdownlist>
</ItemTemplate>
</asp:TemplateField>
<Columns>
</asp:GridView>
Code Behind:
public void chkStatus_Changed(object sender, System.EventArgs e)
{
//......When GridView Checkbox calls event, then it raises an event.
CheckBox chkbox = (CheckBox)(sender);
//......Sender is converted to checkbox and getting its GridView Row by using chkbox.Parent.Parent.
GridViewRow dg = (GridViewRow)(chkbox.Parent.Parent);
//......GridView Row to find the Control or Text of particular cell.
DropDownList ddl = (DropDownList)(dg.Cells[4].FindControl("ddlBatchPriorty"));
}
相关文章推荐
- [转]Raising An Event From CheckBox In A GridView (GridView中模板表的CheckBox的后台事件处理)
- 在GridView控件中的HeaderTemplate模板上添加的CheckBox控件无法引发AutoPostback事件,或无规律的引发,不正常的引发
- #501 – 在对个控件中共享事件处理程序(Sharing an Event Handler Across Multiple Controls)
- ASPxGridView 结合CheckBox实现多选(在后台事件代码控制)
- GridView模板列,如何在后台代码中添加客户端事件,执行sql函数,格式化数据
- ASPxGridView 结合CheckBox实现多选(在后台事件代码控制)
- #606 – 重用(另一个类中)已经存在的路由事件(Reusing an Existing Routed Event in Your Class)
- GridView模板之处理模板中的事件
- 如何处理GridView模板列绑定字段过长的问题(转)
- js 的CheckBox 的全选总结 (Table或GridView中所有的CheckBox处理) j-query的处理
- GridView 激发了未处理的事件“PageIndexChanging”
- DOM2中的高级事件处理(Advanced Event Handling with DOM Level 2)
- Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server.
- 当使用EntityDataSource作为GridView的数据源时,在RowDataBound事件处理方法中得到对应当前行的实体对象
- 事件的传递 event 冒泡处理
- HowTO: Create an Event Log Source in code, without the Permission errors
- GridView“GridView1”激发了未处理的事件“PageIndexChanging”
- jQuery源码分析-10事件处理-Event-事件绑定与删除-bind/unbind+live/die+delegat/undelegate
- 在onTouchEvent中处理任意时间的长按事件
- gridview导出exe处理时遇到RegisterForEventValidation can only be called during Render();错误