set dynamically the href attribute of link inside itemtemplate in radcombobox

2 posts, 0 answers
  1. Tanya
    Tanya avatar
    10 posts
    Member since:
    Apr 2014

    Posted 26 May 2014 Link to this post

    My colleagues has made a radgrid with two gridtemplate columns.The second gridtemplatecolumn consist of radcombobox. As you see this radcombobox has itemtemplate with link; So MY QUESTION IS _ CAN I SET DYNAMIICALLY THIS HREF ATTRIBUTE OF MY LINK


    <te
    lerik:RadGrid ID="RadGridLang" runat="server" AutoGenerateColumns="False"  EnableEmbeddedSkins="False"  RegisterWithScriptManager=false <br>                     DataTextField="Descr" DataValueField="LanImg"<br>                    Height="100%" Width="120px" AppendDataBoundItems="true" CellSpacing="0" GridLines="None" OnLoad="RadGridLang_Load"><br>                    <MasterTableView><br>                        <Columns><br>                            <telerik:GridTemplateColumn DataField="LanCd"><br>                                <ItemTemplate><br>                                    <img src="<%#DataBinder.Eval(Container.DataItem, "LanImg")%>" alt="ASP.NET hosting" /><br>                                </ItemTemplate><br>                            </telerik:GridTemplateColumn><br>                            <telerik:GridTemplateColumn DataField="LanCd"><br>                                <ItemTemplate><br>                                    <telerik:RadComboBox ID="RadComboBoxLang" runat="server" EmptyMessage="Select a language" DataTextField="Descr" DataValueField="LanCd" EnableEventValidation="true"  RegisterWithScriptManager=false <br>                                        EnableLoadOnDemand="true" DataSourceID="ObjectDataSourceDrob" CausesValidation="false" AllowCustomText="true" AppendDataBoundItems="true" OnLoad="RadComboBoxLang_Load"><br>                                         <ItemTemplate><br>                                            <div class="imageWrap"><br>                                                <a href='gfgf'><br>                                                <img src="<%#DataBinder.Eval(Container.DataItem, "LanImg")%>" alt='<%# Eval("Descr")%>'/>&nbsp&nbsp&nbsp&nbsp&nbsp<%#DataBinder.Eval(Container.DataItem, "Descr")%></a><br>                                            </div><br><br>                                        </ItemTemplate><br>                                    </telerik:RadComboBox><br>                                </ItemTemplate><br>                            </telerik:GridTemplateColumn><br>                        </Columns><br>                    </MasterTableView><br>                </telerik:RadGrid>

    And here is my code 


    p
    rotected void RadComboBoxLang_Load(object sender, EventArgs e)<br>        {<br>            String pRequest = pGetLang; <br>            if (HttpContext.Current.Request.RequestContext.RouteData.Values["id"] != null)<br>            {<br>                pRequest = HttpContext.Current.Request.RequestContext.RouteData.Values["id"].ToString();<br>            }<br>            RadComboBox radComboBoxLang = sender as RadComboBox;<br>            radComboBoxLang.Items[0].Attributes["href"] = "lalala";<br>            radComboBoxLang.SelectedValue = pRequest.ToUpper();<br>            bool p_test = MvcBeaDAL.CookiesManager.SetGetCookie(radComboBoxLang.SelectedValue);<br>        }<br>        protected void RadGridLang_Load(object sender, EventArgs e)<br>        {<br>            String pRequest = GetLang();<br>RadGrid pRadGridLang = this.FindControl("RadGridLang") as RadGrid;<br>            List<LanguageHost> radLang = new List<LanguageHost>();<br>            radLang.Add( MvcBeaDAL.WebServiceBea.GetWebLanguageID(pRequest));<br>           string col = pRadGridLang.Columns[0].ColumnType;<br>            pRadGridLang.DataSource = radLang.ToList();<br>            pRadGridLang.DataBind();<br>        }
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 May 2014 in reply to Tanya Link to this post

    Hi Tanya,

    In order to access the Anchor tag inside the ItemTemplate of RadComboBox please do the following modification in your ASPX page. Please try to attach the OnDataBound event of RadComboBox to access the Anchor tag  in code behind.

    ASPX:
    <ItemTemplate>
        <div class="imageWrap">
            <a runat="server" id="navigatePage">
                <img src="<%#DataBinder.Eval(Container.DataItem, "LastName")%>" alt='<%# Eval("LastName")%>' /><%#DataBinder.Eval(Container.DataItem, "LastName")%>
               </
    a>
          </
    div>
    </ItemTemplate>

    C#:
    protected void RadComboBoxLang_DataBound(object sender, EventArgs e)
    {
        RadComboBox radComboBoxLang = sender as RadComboBox;
        HtmlAnchor anchor = (HtmlAnchor)radComboBoxLang.Items[0].FindControl("navigatePage");
        // set the url here
        anchor.HRef = "http://wwww.google.com";
    }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top