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

Event for databinding of gridTemplate column

2 Answers 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
usman
Top achievements
Rank 1
usman asked on 05 Feb 2012, 06:29 PM
I want to conditionally bind the images in telerik:template column but the cs code for it never gets executed 

<telerik:GridTemplateColumn  ItemStyle-Width="40px" ItemStyle-Font-Names="Arial" ItemStyle-Font-Bold="true">
    <ItemTemplate>
     
  <asp:ImageButton ID="vote_up" runat="server"  CommandName="up" />
  <br />
  <%#Eval("likes") %>
  <br />
  <asp:ImageButton ID="vote_down" runat="server"   CommandName="down" />
    </ItemTemplate>
    </telerik:GridTemplateColumn>

the Cs code is 

protected void answer_grid_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridTemplateColumn)
        {
            GridDataItem item = e.Item as GridDataItem;
            ImageButton up_url = item.FindControl("vote_up") as ImageButton;
            ImageButton down_url = item.FindControl("vote_down") as ImageButton;
            if (Eval("expr1").ToString().Equals(cur_mem_id))
            {
                if (Eval("liked").ToString().Equals("TRUE"))
                    up_url.ImageUrl = "~/images/up_no";
            }
            else up_url.ImageUrl = "~/images/up_logo.png";
 
            if (Eval("expr1").ToString().Equals(cur_mem_id))
            {
                if (Eval("liked").ToString().Equals("FALSE"))
                    down_url.ImageUrl = "~/images/down_no.png";
            }
            else down_url.ImageUrl = "~/images/down_logo.png";
 
 
        }
    }
the code in If block never gets executed 

2 Answers, 1 is accepted

Sort by
0
usman
Top achievements
Rank 1
answered on 05 Feb 2012, 06:38 PM
even if I use anyother option in intellisense regarding telerik column types 
if (e.Item is GridTemplateColumn)  
0
Shinu
Top achievements
Rank 2
answered on 06 Feb 2012, 05:04 AM
Hello Usamn,

Try the following code.
C#:
protected void grid_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
  {
   GridDataItem item = (GridDataItem)e.Item;
   ImageButton img = (ImageButton)item.FindControl("vote_up");
    img.ImageUrl = "~/images/up_no";
  }
}

-Shinu.
Tags
Grid
Asked by
usman
Top achievements
Rank 1
Answers by
usman
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or