How do I bind ImageURL for GridButtonColumn of type ImageButton?

3 posts, 1 answers
  1. Henry
    Henry avatar
    14 posts
    Member since:
    Dec 2008

    Posted 14 Apr 2014 Link to this post

    Hi,

    How do I bind ImageURL for GridButtonColumn of type ImageButton? I have the image URL in a database but not sure how I would bind it. Any ideas?

    Regards,

    Henry Fourie
  2. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 14 Apr 2014 in reply to Henry Link to this post

    Hello,

    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false"
        OnNeedDataSource="RadGrid1_NeedDataSource" ondatabound="RadGrid1_DataBound"
        onitemdatabound="RadGrid1_ItemDataBound">
        <MasterTableView>
            <Columns>
                <telerik:GridButtonColumn ButtonType="ImageButton"  UniqueName="MyImageButton">
                </telerik:GridButtonColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("imgPath", typeof(string));
        dt.Rows.Add("MCTS.png");
        RadGrid1.DataSource = dt;
    }
    protected void RadGrid1_DataBound(object sender, EventArgs e)
    {
     
    }
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = e.Item as GridDataItem;
            DataRowView dr = item.DataItem as DataRowView;
            (item["MyImageButton"].Controls[0] as ImageButton).ImageUrl = "~/images/" + dr["imgPath"];
        }
     
    }



    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Henry
    Henry avatar
    14 posts
    Member since:
    Dec 2008

    Posted 16 Apr 2014 in reply to Jayesh Goyani Link to this post

    Great, thanks for this.
Back to Top