LinkButton Comman Argument in ItemTemplate

7 posts, 0 answers
  1. omer
    omer avatar
    65 posts
    Member since:
    Nov 2010

    Posted 21 Sep 2015 Link to this post

    Hello

    I've LinkButton in my RadComboBox ItemTemplate with CommandName OnCommand event and Command Argument for delete item if user clicking.

    ComboBox populating with SqlDataSource. 

    When trying to click second item in ComboBox page postabacking but doesnt raise onclick or even oncommand event. 

    If clicking first item in ComboBox raising both of events but command argument is second items command argument. 

    Where is the mistake?

    Thanks is advance.

  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 21 Sep 2015 Link to this post

    Hi Omer,

    Can you try to register LinkButtton as a AsyncPostBackControl:

    <telerik:RadComboBox runat="server" ID="combo" OnItemDataBound="combo_ItemDataBound"
                   DataSourceID="sdsProducts" DataTextField="ProductName" DataValueField="ProductID">
                   <ItemTemplate>
                       <asp:LinkButton runat="server"  CommandName="Create" Text='<%# Eval("ProductName") %>' ID="LinkBtn" OnClick="LinkBtn_Click"></asp:LinkButton>
                   </ItemTemplate>
               </telerik:RadComboBox>
     
               <asp:SqlDataSource runat="server" ID="sdsProducts" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
                   SelectCommand="SELECT [ProductID], [ProductName] FROM [Alphabetical list of products]"></asp:SqlDataSource>

    protected void combo_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
        {
            LinkButton lb = e.Item.FindControl("LinkBtn") as LinkButton;
            ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(lb); 
        }
        protected void LinkBtn_Click(object sender, EventArgs e)
        {
     
        }

    Regards,
    Hristo Valyavicharski
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. omer
    omer avatar
    65 posts
    Member since:
    Nov 2010

    Posted 21 Sep 2015 Link to this post

    Than you for reply!

    Added yor code to my itemdatabound but did not work.

    <telerik:RadComboBox runat="server" ID="RadComboBoxDeliveryAdresses"
    Width="300px"
     
    DropDownWidth="300px" DropDownHeight="300px"                                                   
                                                        HighlightTemplatedItems="true"
                                                        DataValueField="AdressId"
                                                        DataTextField="AdressName"                                                   
                                                        OnItemsRequested="RadComboBoxDeliveryAdresses_ItemsRequested"
                                                        OnItemDataBound="RadComboBoxAdresses_ItemDataBound">
                                                        <DefaultItem Text="Lütfen bir Teslimat adresi seçin." CssClass="rcbItem" />                                                   
                                                        <ItemTemplate>
                                                            <table border="1" cellspacing="0" cellpadding="0" style="border-collapse: collapse; border: none">
                                                                <tbody>
                                                                    <tr>
                                                                        <td width="170" valign="top" style="width: 127.2pt; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelAdressName" Text="Adres Tanımı"></asp:Label>
                                                                        </td>
                                                                        <td width="142" valign="top" style="width: 106.3pt; border-left: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelAdressNameData"
                                                                                Text='<%# DataBinder.Eval(Container.DataItem, "AdressName")%>'></asp:Label>
                                                                        </td>
                                                                        <td width="38" rowspan="11" valign="middle" style="width: 1.0cm; border-left: none;
                                                                            padding: 0cm 5.4pt 0cm 5.4pt">                                                                     
                                                                            <asp:LinkButton ID="LinkButtonDeleteDeliveryAdress"
                                                                                runat="server"                                                                           
                                                                                CausesValidation="false"
                                                                                ForeColor="navy" Text='<%# Eval("AdressId") %>'
                                                                                CommandArgument='<%# Eval("AdressId") %>'
                                                                                CommandName="Delete" OnCommand="LinkButtonDelete_Command"
                                                                                ></asp:LinkButton>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td width="170" valign="top" style="width: 127.2pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelInVoiceType" Text="Fatura Tipi"></asp:Label>
                                                                        </td>
                                                                        <td width="142" valign="top" style="width: 106.3pt; border-top: none; border-left: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelInvoiceTypeData"
                                                                                Text='<%# DataBinder.Eval(Container.DataItem, "InvoiceType") %> '></asp:Label>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td width="170" valign="top" style="width: 127.2pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelContact" Text="İlgili"></asp:Label>
                                                                        </td>
                                                                        <td width="142" valign="top" style="width: 106.3pt; border-top: none; border-left: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelContactNameData" Text='<%# DataBinder.Eval(Container.DataItem, "ContactName")%>'> </asp:Label>
                                                                            <asp:Label runat="server" ID="LabelContactSurNameData" Text='<%# DataBinder.Eval(Container.DataItem, "ContactSurName")%>'></asp:Label>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td width="170" valign="top" style="width: 127.2pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelContactNumber" Text="İletişimNo"></asp:Label>
                                                                        </td>
                                                                        <td width="142" valign="top" style="width: 106.3pt; border-top: none; border-left: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelContactNumberData" Text='<%# DataBinder.Eval(Container.DataItem, "ContactNumber")%>'></asp:Label>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td width="170" valign="top" style="width: 127.2pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelCity" Text="Şehir"></asp:Label>
                                                                        </td>
                                                                        <td width="142" valign="top" style="width: 106.3pt; border-top: none; border-left: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelCityData" Text='<%# DataBinder.Eval(Container.DataItem, "City")%>'></asp:Label>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td width="170" valign="top" style="width: 127.2pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelDistrict" Text="İlçe"></asp:Label>
                                                                        </td>
                                                                        <td width="142" valign="top" style="width: 106.3pt; border-top: none; border-left: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelDistrictData" Text='<%# DataBinder.Eval(Container.DataItem, "District")%>'></asp:Label>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td width="170" valign="top" style="width: 127.2pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelPart" Text="Mahalle"></asp:Label>
                                                                        </td>
                                                                        <td width="142" valign="top" style="width: 106.3pt; border-top: none; border-left: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelPartData" Text='<%# DataBinder.Eval(Container.DataItem, "Part")%>'></asp:Label>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td width="170" valign="top" style="width: 127.2pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelOtherInformation" Text="Cadde/Sokak/KapıNo:"></asp:Label>
                                                                        </td>
                                                                        <td width="142" valign="top" style="width: 106.3pt; border-top: none; border-left: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelOtherInformationData" Text='<%# DataBinder.Eval(Container.DataItem, "OtherInformation")%>'></asp:Label>
                                                                        </td>
                                                                    </tr>
                                                                    <tr runat="server" id="trcompanyname">
                                                                        <td width="170" valign="top" style="width: 127.2pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelCompanyName" Text="Firma:"></asp:Label>
                                                                        </td>
                                                                        <td width="142" valign="top" style="width: 106.3pt; border-top: none; border-left: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelCompanyNameData" Text='<%# DataBinder.Eval(Container.DataItem, "CompanyName")%>'></asp:Label>
                                                                        </td>
                                                                    </tr>
                                                                    <tr runat="server" id="trcompanytaxoffice">
                                                                        <td width="170" valign="top" style="width: 127.2pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelCompanyTaxOffice" Text="Vergi Dairesi:"></asp:Label>
                                                                        </td>
                                                                        <td width="142" valign="top" style="width: 106.3pt; border-top: none; border-left: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelCompanyTaxOfficeData" Text='<%# DataBinder.Eval(Container.DataItem, "CompanyTaxOffice")%>'></asp:Label>
                                                                        </td>
                                                                    </tr>
                                                                    <tr runat="server" id="trcompanytaxid">
                                                                        <td width="170" valign="top" style="width: 127.2pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelCompanyTaxId" Text="Vergi No:"></asp:Label>
                                                                        </td>
                                                                        <td width="142" valign="top" style="width: 106.3pt; border-top: none; border-left: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                            <asp:Label runat="server" ID="LabelCompanyTaxIdData" Text='<%# DataBinder.Eval(Container.DataItem, "CompanyTaxId")%>'></asp:Label>
                                                                        </td>
                                                                    </tr>
                                                                </tbody>
                                                            </table>
                                                        </ItemTemplate>
                                                        <FooterTemplate>
                                                            <tr>
                                                                <td width="auto" valign="baseline" style="width: 232.5pt; border: solid windowtext 1.0pt; border-top: none; padding: 0cm 5.4pt 0cm 5.4pt">
                                                                    <p class="MsoNormal" style="margin-bottom: 0cm; margin-bottom: .0001pt; line-height: normal; vertical-align: middle">
                                                                        <asp:LinkButton runat="server" ID="LinkButtonAddNewDeliveryAdress" Text="Yeni Adres Ekle"
                                                                            CommandName="Add" ForeColor="Gray" CausesValidation="false"
                                                                            OnCommand="LinkButtonAddNew_Command"
                                                                            Width="135" Font-Size="Larger" Font-Bold="true" CssClass="center"></asp:LinkButton>
                                                                    </p>
                                                                </td>
                                                            </tr>
     
                                                        </FooterTemplate>
                                                    </telerik:RadComboBox>

  5. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 21 Sep 2015 Link to this post

    Can you paste the OnItemDataBount event of the combo?

    Thanks.

    Regards,
    Hristo Valyavicharski
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. omer
    omer avatar
    65 posts
    Member since:
    Nov 2010

    Posted 21 Sep 2015 in reply to Hristo Valyavicharski Link to this post

    Thank you for reply
    Here is my onitemdatabound event
    protected void RadComboBoxAdresses_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
        {
            if (e.Item is RadComboBoxItem)
            {
     
                DataRowView dataItem = (DataRowView)e.Item.DataItem;
                int count = dataItem.DataView.Count;
     
                Label LabelCompanyName = (Label)RadComboBoxDeliveryAdresses.Items[0].FindControl("LabelCompanyName");
                Label LabelCompanyNameData = (Label)RadComboBoxDeliveryAdresses.Items[0].FindControl("LabelCompanyNameData");
                Label LabelCompanyTaxOffice = (Label)RadComboBoxDeliveryAdresses.Items[0].FindControl("LabelCompanyTaxOffice");
                Label LabelCompanyTaxOfficeData = (Label)RadComboBoxDeliveryAdresses.Items[0].FindControl("LabelCompanyTaxOfficeData");
                Label LabelCompanyTaxId = (Label)RadComboBoxDeliveryAdresses.Items[0].FindControl("LabelCompanyTaxId");
                Label LabelCompanyTaxIdData = (Label)RadComboBoxDeliveryAdresses.Items[0].FindControl("LabelCompanyTaxIdData");
     
               // LinkButton lb = e.Item.FindControl("LinkButtonDeleteDeliveryAdress") as LinkButton;
     
                LinkButton LinkButtonDeleteDeliveryAdress = (LinkButton)RadComboBoxDeliveryAdresses.Items[0].FindControl("LinkButtonDeleteDeliveryAdress");
                LinkButton lb = e.Item.FindControl("LinkBtn") as LinkButton;
                //ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(lb);
                try
                {
                    AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
                    trigger.ControlID = lb.UniqueID;
                    trigger.EventName = "Click"; //like "Click", "IndexChanged", etc.
                    this.UpdatePanelAdress.Triggers.Add(trigger);
                }
                catch
                {
                    //Your exception management
                }
                HtmlTableRow trcompanyname = (HtmlTableRow)e.Item.FindControl("trcompanyname");
                HtmlTableRow trcompanytaxoffice = (HtmlTableRow)e.Item.FindControl("trcompanytaxoffice");
                HtmlTableRow trcompanytaxid = (HtmlTableRow)e.Item.FindControl("trcompanytaxid");
     
     
                if (count == 1)
                {
                    LinkButtonDeleteDeliveryAdress.Visible = false;
                }
                if (dataItem["InvoiceType"].ToString() == "Bireysel")
                {
                    trcompanyname.Visible = false;
                    trcompanytaxoffice.Visible = false;
                    trcompanytaxid.Visible = false;
                    LabelCompanyName.Visible = false;
                    LabelCompanyNameData.Visible = false;
                    LabelCompanyTaxOffice.Visible = false;
                    LabelCompanyTaxOfficeData.Visible = false;
                    LabelCompanyTaxId.Visible = false;
                    LabelCompanyTaxIdData.Visible = false;
                }
                else
                {
                    trcompanyname.Visible = true;
                    trcompanytaxoffice.Visible = true;
                    trcompanytaxid.Visible = true;
                }
            }
     
        }
  7. omer
    omer avatar
    65 posts
    Member since:
    Nov 2010

    Posted 21 Sep 2015 in reply to omer Link to this post

    RadComboBox loading in run time. 

    Removed if (!Is.Postback) check and now when clicking LinkButton firing ItemdataBound always.

    But firing oncommand event only when I clicking first item with wrong command argument.(second items command argument)

  8. omer
    omer avatar
    65 posts
    Member since:
    Nov 2010

    Posted 21 Sep 2015 Link to this post

    Only first item firing OnCommandEvent.

    I achieve this issue with this codes

    //aspx
    <input type="button" id="btnDelete" onclick='<%# String.Format("javascript:return SaveWithParameter(\"{0}\")", Eval("AdressId").ToString()) %>'  value="Sil"/>                                                                       
    //javascript
        <script type="text/javascript">
            function SaveWithParameter(parameter) {
                __doPostBack('btnDelete', parameter)
            }
    </script>
    //cs
      if (Request["__EVENTARGUMENT"] != null && Request["__EVENTTARGET"] != null)
            {
                string parameter = Request["__EVENTARGUMENT"]; // parameter
                string target = Request["__EVENTTARGET"]; // btnSave
                if (target == "btnDelete")
                {
                    SqlDataSourceAdress.DeleteParameters["AdressId"].DefaultValue = parameter;
                    SqlDataSourceAdress.Delete();
                }
            }

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017