gridview的删除命令中的控制值 [英] control value in delete command of gridview

查看:37
本文介绍了gridview的删除命令中的控制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的网格视图为:

Hi all ,

I have gridview as :

<asp:GridView ID="GrvCancelLeave" Width="80%" runat="server" CellPadding="4" ForeColor="#333333"

            GridLines="None" AutoGenerateColumns="False" DataKeyNames="AttendanceId"

            Font-Names="Verdana" Font-Size="Small"

            onrowdeleting="GrvCancelLeave_RowDeleting">
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#EFF3FB" />
            <Columns>
                <asp:BoundField DataField="Date" ItemStyle-HorizontalAlign="Center" HeaderText="Date" />
                <asp:BoundField DataField="DayName" ItemStyle-HorizontalAlign="Center" HeaderText="Day" />
                <asp:BoundField DataField="Remark" ItemStyle-HorizontalAlign="Center" HeaderText="Remark" />
                <asp:CommandField DeleteText="Cancel Leave" ShowDeleteButton="True" />
            </Columns>
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>



在后面的代码中,我写了类似




and in code behind i wrote something like


protected void GrvCancelLeave_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

string AttendanceId = GrvCancelLeave.DataKeys[e.RowIndex].Value.ToString();
        Label LeaveType = (Label)GrvCancelLeave.Rows[e.RowIndex].Cells[2].Controls[0];
}



它显示错误,因为索引超出标签范围.
如果我在任何地方都不对,请帮助我解决问题.

谢谢



it is showing error as index out of range in label.
Please help me in sorting my problem if I am wrong anywhere.

Thanks

推荐答案

您没有在网格视图中使用任何模板字段,而是尝试将法线绑定字段转换为标签字段..
尝试在模板字段中使用标签控件,然后检索
You are not using any template fields in the grid view, but trying to convert normal bound fields to label fields..
Try using label control inside template field, and retrieve


这篇关于gridview的删除命令中的控制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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