This is a migrated thread and some comments may be shown as answers.

How to use DataBinder in RadButton ImageUrl Property?

1 Answer 88 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ashkan
Top achievements
Rank 1
Ashkan asked on 12 Nov 2014, 07:10 PM
Hi.
i need to ImageUrl with databinder in radgrid GridTemplateColumn:
MyCode in aspx:
<telerik:GridTemplateColumn HeaderText="Need Call"
                            ItemStyle-HorizontalAlign="Center"  >
    <ItemTemplate>
        <telerik:RadToolTip ID="RadToolTipCall" runat="server" TargetControlID="chkNeedCall" AutoCloseDelay="10000"
                            RelativeTo="Element" Position="MiddleRight">
            <%# Eval("UsernameNeedCall") %>
        </telerik:RadToolTip>
        <telerik:RadButton ID="chkNeedCall" runat="server" Width="22px" Height="22px" ToggleType="CheckBox" ButtonType="LinkButton" CommandArgument='<%# Eval("Id") %>' AutoPostBack="True" OnCommand="btnNeedCall_Click">
           <Image EnableImageButton="True" ImageUrl='<%# Eval("NeedCall") %>' IsBackgroundImage="True"></Image>
        </telerik:RadButton>
    </ItemTemplate>
</telerik:GridTemplateColumn>

C# Code:
protected void gridShow_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    try
    {
        if (!e.IsFromDetailTable)
        {
            var db = new MyDataContext();
            var reciveMsg = db.TBL_ReceiverMsgs.ToList().Select((c, index) => new
            {
                RowIndex = index + 1,
                c.Id,
                c.Body,
                NeedCall = c.NeedCall ? "../Images/Sms/deliveryorange.png" : "../Images/Sms/deliveryok.png",
                NeedFollow = c.NeedFollow ? "../Images/Sms/deliveryorange.png" : "../Images/Sms/deliveryok.png",
                c.UsernameNeedCall
 
            });
            gridShowSms.DataSource = reciveMsg;
        }
 
 
    }
    catch (Exception)
    {
        lblException.Text = @"Error!!";
    }
}

Error in Line:<%# Eval("NeedCall") %>
how to fix the problem?
-------------------------------
I also have another problem:
when use the label or literal or div in GridTemplateColumn, radgrid columns mixed.
but MaxLength property!!! MaxLength does not allow mixed up columns.
The GridBoundColumn can not be used from RadToolTip!
<telerik:GridTemplateColumn HeaderText="Body" ItemStyle-HorizontalAlign="Center" >
    <ItemTemplate>
        <telerik:RadToolTip ID="RadToolTipBody" runat="server" TargetControlID="lblBody"
                            RelativeTo="Element" Position="Center" >
            <%# DataBinder.Eval(Container, "DataItem.Body") %>
        </telerik:RadToolTip>
        <div style="Width:100px" ID="lblBody" runat="server"><%# Eval("Body") %></div>
    </ItemTemplate>
</telerik:GridTemplateColumn>

TIA...

1 Answer, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 17 Nov 2014, 02:24 PM
Hi Ashkan,

I noticed that you have add the image control in a RadButton. Note that when using an Evel expression it will looks for a filed in the RadButton and not in the RadGrid. Since RadButton does not have a DataBind method you can not use an Eval expression. Nevertheless a possible solution is to use a Hyperlink control. Regards your second question I am afraid I am not completely understand what is the issue which you are facing. Could you please elaborate a little bit more on the matter?

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Ashkan
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Share this question
or