參考Link loaded into my gridview try to navigate to my local server。我在數據網格中的列是Customer#,Description,Link。如何編輯綁定到數據網格的數據?
我有一個函數在rowDataBound上調用,但是如何檢索行中的鏈接,以便我可以編輯它,然後將它重新綁定到datagrid?
protected void grdLinks_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex == 2)
{
}
}
這裏是我的GridView控件代碼
<asp:GridView ID="grdLinks" runat="server" AutoGenerateColumns="False" DataSourceID="ldsCustomerLinks"
OnRowDataBound="grdLinks_RowDataBound" EmptyDataText="No data was returned."
DataKeyNames="ID" OnRowDeleted="grdLinks_RowDeleted" Width="80%" BackColor="White"
HorizontalAlign="Center" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3" GridLines="Vertical">
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<Columns>
<asp:BoundField DataField="CustomerNumber" HeaderText="Customer Number" SortExpression="CustomerNumber" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:HyperLinkField DataTextField="Link" HeaderText="Link" SortExpression="Link" DataNavigateUrlFields="Link" Target="_blank" />
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="ldsCustomerLinks" runat="server" ContextTypeName="ComplianceDataContext"
TableName="CustomerLinks" EnableDelete="true">
</asp:LinqDataSource>
是的,這就是我想要的。但是,如何在修改後在數據網格中顯示更新後的鏈接? – Justen 2009-12-31 16:14:10
假設鏈接控件是在網格中定義的,那麼你會想要做一個DOK提到的FindControl,並用你抓取的值來設置它。 – CAbbott 2009-12-31 16:16:00
FindControl被設置爲等於HyperLink變量。我如何將HyperLink變量轉換爲字符串,然後返回到HyperLink? – Justen 2009-12-31 16:49:44