krishna mohan
krishna mohan

Reputation: 267

Specified argument was out of the range of valid values - RowDataBound

I want to change navigate url property in row data bound event. if that coloumn not binded with link i want to add navigate url= #

<asp:TemplateField HeaderText="Reportd Link"  ItemStyle-HorizontalAlign="center" >
                    <ItemTemplate>
                   <asp:HyperLink ID="Lbl_RptLnk1" runat="server" NavigateUrl='<%#Eval("ReportLinks")%>'
                            Text='Reported Link' Target="_blank" ToolTip='<%#Eval("ReportLinks")%>'></asp:HyperLink>

                 </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>

aspx.cs code

  if (e.Row.RowType == DataControlRowType.DataRow)
    {
        HyperLink myLink = (HyperLink)e.Row.Cells[4].Controls[0];//slno,linkname,linkid,link

        if (myLink.NavigateUrl == "Waiting for Approval")
        {
            myLink.NavigateUrl = "#";
        }

    }

getting error saying- Specified argument was out of the range of valid values. Parameter name: index

Upvotes: 0

Views: 627

Answers (1)

Rahul Singh
Rahul Singh

Reputation: 21825

In RowDataBound event since your control is an ASP server control inside TemplateField, you can use the FindControl method on the row to find the control:-

HyperLink Lbl_RptLnk1 = (HyperLink)e.Row.FindControl("Lbl_RptLnk1");
if (Lbl_RptLnk1.NavigateUrl.Trim() == "Waiting for Approval")
{
     Lbl_RptLnk1.NavigateUrl = "#";
}

Upvotes: 1

Related Questions