Manipulating Grid column - Adding link button

2 posts, 0 answers
  1. Vijaianand
    Vijaianand avatar
    82 posts
    Member since:
    Jul 2012

    Posted 05 Jan 2012 Link to this post

    I have radgrid with itemplate for every column like below
    <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="Vertical" Skin="Hay" PageSize="250"
          AllowSorting="True" AllowPaging="True" ShowGroupPanel="False" AutoGenerateColumns="false"
          Width="100%" >
          <PagerStyle Mode="Slider"></PagerStyle>
          <MasterTableView ShowGroupFooter="true" GroupsDefaultExpanded="False" HeaderStyle-HorizontalAlign="Center"
              GroupHeaderItemStyle-BackColor="white" GroupHeaderItemStyle-ForeColor="Black"
              GroupHeaderItemStyle-Font-Size="Medium" DataKeyNames="SkillID">
              <GroupByExpressions>
                  <telerik:GridGroupByExpression>
                      <SelectFields>
                          <telerik:GridGroupByField FieldName="SkillAreaId" HeaderText=" " />
                          <telerik:GridGroupByField FieldName="SkillArea" HeaderText=" " />
                      </SelectFields>
                      <GroupByFields>
                          <telerik:GridGroupByField FieldName="SkillAreaId" HeaderText="" HeaderValueSeparator=" " />
                      </GroupByFields>
                  </telerik:GridGroupByExpression>
              </GroupByExpressions>
              <Columns>
                  <telerik:GridTemplateColumn  UniqueName="SkillID">
                      <ItemTemplate>
                          <b>
                              <%# Eval("SkillID")%>
                          </b>
                      </ItemTemplate>
                      <FooterTemplate>
                      </FooterTemplate>
                  </telerik:GridTemplateColumn>
                  <telerik:GridTemplateColumn>
                      <ItemTemplate>
                          <%# Eval("Skill")%>
                      </ItemTemplate>
                  </telerik:GridTemplateColumn>
                  <telerik:GridTemplateColumn>
                      <HeaderTemplate>
                          None<br />
                          0</HeaderTemplate>
                      <ItemTemplate>
                          <asp:RadioButton ID="RadioButton1" runat="server" /></ItemTemplate>
                  </telerik:GridTemplateColumn>
                  <telerik:GridTemplateColumn>
                      <HeaderTemplate>
                          Basic<br />
                          1</HeaderTemplate>
                      <ItemTemplate>
                          <asp:RadioButton ID="RadioButton2" runat="server" /></ItemTemplate>
                  </telerik:GridTemplateColumn>

    I  been trying to access each column in the grid to add a link button for each row with the same event attached to all the link button. But I am stuck at even getting the column value or adding link button to the column. I tried below,

    Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemDataBound
     
    If TypeOf e.Item Is GridDataItem Then
                Dim itm As GridDataItem = CType(e.Item, GridDataItem)
     itm("SkillId").Controls.Add(New LiteralControl("test"))
    End If


    But nothing works. I just simply want to get the value of the column first and embed a link button to the column and trigger a common event. Help me out. 
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Jan 2012 Link to this post

    Hello,

    Try the following code.
    VB:
    Protected Sub RadGrid1_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
        If TypeOf e.Item Is GridDataItem Then
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
            Dim cell As TableCell = DirectCast(item("SkillID"), TableCell)
            Dim btn As New LinkButton()
            btn.ID = "Link"
            cell.Controls.Add(btn)
        End If
    End Sub

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top