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

How do I bind ImageURL for GridButtonColumn of type ImageButton?

2 Answers 198 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Henry
Top achievements
Rank 2
Henry asked on 14 Apr 2014, 02:34 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 14 Apr 2014, 05:10 PM
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
0
Henry
Top achievements
Rank 2
answered on 16 Apr 2014, 10:04 AM
Great, thanks for this.
Tags
Grid
Asked by
Henry
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Henry
Top achievements
Rank 2
Share this question
or