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

Grid dummy columns

1 Answer 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
iomega 55
Top achievements
Rank 1
iomega 55 asked on 27 Jun 2012, 12:06 AM
Hi. I need to have 2 dummy columns (column with no reference to a field in the database) in a radgrid. Each one of these columns need to have a javascript call, this javascript must be set on the itemdatabound event placing the value of the 3rd column (client id) inside the javascript call of the previous two dummy columns.

How can I do this? Create the 2 dummy columns and reference them in the itemdatabound for placing the javascript on it.

Thanks in advance.

1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 29 Jun 2012, 08:07 AM
Hello Iomega,

You could try adding two GridTemplateColumns with labels into theirs ItemTemplates:
<telerik:GridTemplateColumn HeaderText="Column1" UniqueName="Column1">
                  <ItemTemplate>
                      <asp:Label runat="server" ID="Label1"></asp:Label>
                  </ItemTemplate>
              </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Column1" UniqueName="Column2">
                  <ItemTemplate>
                      <asp:Label ID="Label2" runat="server"></asp:Label>
                  </ItemTemplate>
              </telerik:GridTemplateColumn>

Then on ItemDataBound you could find these labels and set some javascript as a text:
void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            GridDataItem item = e.Item as GridDataItem;
            if (item != null)
            {
                Label l1 = item["Column1"].FindControl("Label1") as Label;
                Label l2 = item["Column1"].FindControl("Label2") as Label;
 
                l1.Text = "<script type='text/javascript'>alert(1)</script>";
                l2.Text = "<script type='text/javascript'>alert(2)</script>";
            }
        }

Please give it try and let me know if it helps you. Looking forward for your reply.

Regards,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
iomega 55
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or