网格视图按钮事件asp.net [英] Grid view button event asp.net

查看:44
本文介绍了网格视图按钮事件asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:GridView ID="grdViewManualAttendance" runat="server" AutoGenerateColumns="False"

                                        BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"

                                         EnableViewState="False" Font-Size="Small" Width="680px"

                                      

                                        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                                        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                                        <Columns>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                                <asp:Button ID="btnDelete" runat="server" Text="Delete"

                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <asp:CheckBox ID="chkDelete" runat="server" />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                            <asp:BoundField DataField="AttendanceID" HeaderText="AttendanceID" ItemStyle-Width="20px" />
                                            <asp:BoundField DataField="Date" DataFormatString="{0:dd/mm/yyyy}" HeaderText="Date"

                                                ItemStyle-Width="20px" />
                                            <asp:BoundField DataField="Time" DataFormatString="{0:hh:mm:ss}" HeaderText="Time" ItemStyle-Width="20px" />
                                            <asp:BoundField DataField="GraceTime" HeaderText="GraceTime"

                                                ItemStyle-Width="20px" />
                                                <asp:BoundField DataField="IsActive" HeaderText="IsActive"

                                                ItemStyle-Width="20px" />

                                                <asp:BoundField DataField="Remarks" HeaderText="Remarks"

                                                ItemStyle-Width="20px" />


                                                <asp:BoundField DataField="IsAutomaticPull" HeaderText="IsAutomaticPull"

                                                ItemStyle-Width="20px" />
                                                <asp:BoundField DataField="IsLate" HeaderText="IsLate"

                                                ItemStyle-Width="20px" />
                                                 <asp:HyperLinkField DataNavigateUrlFields="AttendanceID" DataNavigateUrlFormatString="ManualAttendance.aspx?AttendanceID={0}&amp;Flag=y"

                                                HeaderText="Edit" Text="Edit">
                                                <ItemStyle Width="20px" VerticalAlign="Middle" HorizontalAlign="Center" />
                                            </asp:HyperLinkField>

                                        </Columns>
                                        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                                        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                                        <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                                        <AlternatingRowStyle BackColor="#DCDCDC" />
                                    </asp:GridView>


这是我的网格视图...在这里我找不到删除按钮事件.行命令事件不起作用.如何解决.pls帮助我


This is my grid view...Here i cant find delete button event. And Row command event not work .How can i solve it .pls help me

推荐答案

尝试一下

Try this

protected void Button2_Click1(object sender, EventArgs e)
    {
        GridViewRow header = GridView1.HeaderRow;
        Button ddlCol = header.FindControl("Button2") as Button;

        if (ddlCol != null)
        {
            // Retrieve value 
            Response.Write(ddlCol.Text);
        }
    }



谢谢



Thanks


如果您在页面加载时填充了此网格,请确保您已在
中编写了代码 if(!IsPostBack)
{
//在此处编写代码以填充网格
}
阻止...

进行删除按钮事件...在设计视图中打开您的aspx页面...选择ur网格视图.您会发现>右上角的箭头..单击它...然后选择编辑模板字段选项...然后从列表中选择您的模板字段..然后您可以找到该按钮..选择该按钮并双击它. ...您将获得删除按钮的Click事件
if u fill this grid at the time of page load make sure that u have written code in
if(!IsPostBack)
{
// here write code to fill grid
}
block...

to take the Delete button event... open ur aspx page in design view... select ur grid view.. u will find > arrow at the upper right corner.. click on it... then select edit template field option...then select ur template field from the list.. then u can find the button.. select that button and double click on it.... u will get the Click event of delete button


添加
CommandName="Delete" 

到您的asp:Button.

to your asp:Button.


这篇关于网格视图按钮事件asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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