在Gridview's Row bounbounevent中查找ButtonField
本文关键字:bounbounevent 查找 ButtonField Row Gridview | 更新日期: 2023-09-27 18:19:00
这是我的内联代码:
<asp:GridView ID="GrdVacation" runat="server" DataKeyNames="ID" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="S.No">
<HeaderTemplate>
Sno</HeaderTemplate>
<ItemTemplate>
<%#Container.DataItemIndex + 1%>
</ItemTemplateField>
</asp:TemplateField>
<asp:BoundField HeaderText="Badge No" DataField="EmpBadge" />
<asp:BoundField HeaderText="Last Vacation Date" DataField="LastVacDate" DataFormatString="{0:dd-MMM-yyyy}" />
<asp:BoundField HeaderText="Vacation Expiry Date" DataField="VacValidity" DataFormatString="{0:dd-MMM-yyyy}" />
<asp:BoundField HeaderText="Vacation Start Date" DataField="VacStartDate" DataFormatString="{0:dd-MMM-yyyy}" />
<asp:BoundField HeaderText="Vacation End Date" DataField="VacEndDate" DataFormatString="{0:dd-MMM-yyyy}" />
<asp:BoundField HeaderText="13 Salary Request" DataField="E13SalRequest" />
<asp:ButtonField ButtonType="Image" CommandName="select" HeaderText="Edit" ImageUrl="~/images/Edit.png"></asp:ButtonField>
</Columns>
</asp:GridView>
我即将在GridView RowDataBound事件的某些条件下改变buttonfield的图像URL。
Code what i have been far,
Protected Sub GrdVacation_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GrdVacation.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim NM = CType(e.Row.Cells(0).Controls(7), ImageButton)
if(true) Then
NM.ImageURL="somepath"
End If
当指定的参数超出有效值范围时,我得到异常。
变化
Dim NM = CType(e.Row.Cells(0).Controls(7), ImageButton)
Dim NM = CType(e.Row.Cells(7).Controls(0), ImageButton)
:
Protected Sub GrdVacation_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GrdVacation.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
//// Dim NM = CType(e.Row.Cells(0).Controls(7), ImageButton)
Dim NM = CType(e.Row.Cells(7).Controls(0), ImageButton)
if(true) Then
NM.ImageURL="somepath"
End If