简体   繁体   中英

Devexpress Get gridview cell as hyperlink

I want to loop and edit the hyperlinks in my devexpress's gridview

    protected void ASPxGridView1_DataBound(object sender, EventArgs e)
    {
        for (int i = 0; i < ASPxGridView1.VisibleRowCount; i++)
        {
            DataRow row = ASPxGridView1.GetDataRow(i);
            ASPxHyperLink hl = row["MyColumnName"] as ASPxHyperLink;
            hl.Text = "something";
        }
    }

Object reference not set to an instance of an object. error points to hl.text = "something";

How do I convert the row into a hyperlink properly? row["MyColumnName"].ToString() returns the text of the cell

Refer these:
Find controls in the DataItem template of ASPxGridView column
The general technique of using the Init/Load event handler
Finding controls within Devexpress ASPxGridView

Either you can use the HtmlRowCreated event then you can fine control with various method provided by ASPxGridView API. There is another way that you can use the Init event of the Hyperlink control and at this event you can customize the control and also review the " How to access controls used as my Grid templates " article for details.

protected void ASPxHyperLink1_Init(object sender, EventArgs e) {
ASPxHyperLink myLink =(ASPxHyperLink)sender;
int key = Convert.ToInt32(ASPxGridView.GetDetailRowKeyValue(myLink.NamingContainer));
}

References:
ASPxGridView Hyperlink NavigateUrl at Runtime

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM