2014-10-01 68 views
0

我跑進了一堵牆,可以使用一些建議。我有一個gridview,每行包含一個「Details」超鏈接。當我處於編輯模式(內聯)時,我想要禁用詳細信息鏈接。我認爲這很簡單,但我似乎無法使其工作。我本以爲(錯誤的),我可以這樣做:如何從_RowEditing Sub訪問gridview中的超鏈接控件?

Dim lnkDetails As HyperLink = CType(e.Row.FindControl("lnkDetails"), HyperLink) 
lnkDetails.Enabled = False 

這裏的問題,因爲我發現,是「電子作爲GridViewEditEventArgs」我子的部分不包括「行」。

下面是相關代碼:

Protected Sub gvCurRecords_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs) 
     ' Make the GridView control into edit mode for the selected row. 
     gvCurRecords.EditIndex = e.NewEditIndex 

     ' Rebind the GridView control to show data in edit mode. 
     BindGridView() 

     ' Hide the Add button. 
     lbtnAdd.Visible = False 
End Sub 

HTML(只有相關列):

<asp:GridView ID="gvCurRecords" CellPadding="4" DataSourceId="SqlDataSource1" 
     Autogeneratecolumns="false" AutoGenerateEditButton="true" 
     AutoGenerateDeleteButton="true" OnRowEditing="gvCurRecords_RowEditing" 
     OnRowCancelingEdit="gvCurRecords_RowCancelingEdit" 
     OnRowUpdating="gvCurRecords_RowUpdating" DataKeyNames="eventID" 
     OnRowDataBound="gvCurRecords_RowDataBound" 
     OnPageIndexChanging="gvCurRecords_PageIndexChanging" runat="server"> 
     <Columns> 
      <asp:TemplateField> 
       <ItemTemplate> 
        <asp:HyperLink ID="lnkDetails" runat="server" Text='Details'  NavigateUrl='<%#FormatUrl(CInt(Eval("EventID")))%>' /> 
       </ItemTemplate> 
      </asp:TemplateField> 
     </Columns> 
    </asp:Gridview> 

任何幫助將不勝感激。謝謝。

回答

1

使用編輯模板來定義,而不是超鏈接標籤:

<EditItemTemplate> 
    <asp:Label ID="lbDetails" runat="server" Text='something else' /> 
</EditItemTemplate> 
+0

嗯......該死。是的,那會工作。 *臉掌* – Wilock 2014-10-01 19:37:32

+0

=)............. – OneFineDay 2014-10-01 19:39:18