首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Gridview的Row DataBound事件中查找DataBound

在Gridview的Row DataBound事件中查找DataBound
EN

Stack Overflow用户
提问于 2014-08-21 10:40:31
回答 1查看 2.3K关注 0票数 0

以下是我的内联代码:

代码语言:javascript
复制
<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事件中的某些条件下更改的图像URL。

到目前为止我尝试过的密码,

代码语言:javascript
复制
   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

我得到了异常,因为指定的参数超出了有效值的范围。请告诉我哪里出了问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-21 11:35:49

变化

代码语言:javascript
复制
Dim NM = CType(e.Row.Cells(0).Controls(7), ImageButton)

代码语言:javascript
复制
Dim NM = CType(e.Row.Cells(7).Controls(0), ImageButton)

如下所示:

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25424259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档