[英]Find ButtonField in Gridview's Row DataBound Event
Here is my Inline Code: 这是我的内联代码:
<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>
I am about to Change the Image URL of the ButtonFiled on some condition in GridView RowDataBound event. 我将在GridView RowDataBound事件中的某些情况下更改ButtonFiled的图像URL。
The Code what i have tried so 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
I am getting exception as Specified argument was out of the range of valid values. 由于指定的参数超出了有效值范围,因此出现异常。 Please suggest me what went wrong.
请建议我出了什么问题。
Change 更改
Dim NM = CType(e.Row.Cells(0).Controls(7), ImageButton)
to 至
Dim NM = CType(e.Row.Cells(7).Controls(0), ImageButton)
Like this: 像这样:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.