Current Column Index???

4 posts, 0 answers
  1. Alexander
    Alexander avatar
    152 posts
    Member since:
    Jun 2012

    Posted 18 Mar 2011 Link to this post

    Let's say i have something like this:
    <Columns>
        <telerik:GridTemplateColumn HeaderStyle-CssClass='GridHeaderGreen ra' ItemStyle-CssClass='ra'
            HeaderText='#' ItemStyle-Width='25' HeaderStyle-Width='25'>
            <ItemTemplate>
                <asp:Label ID="lblRowNum" runat="server" />
            </ItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridBoundColumn HeaderStyle-CssClass='GridHeaderGreen la' ItemStyle-CssClass='la' HeaderText='Server Name' SortExpression='TSM.TSMSERVER.NAME' DataField='Server_name' UniqueName='Server_name' />
        <telerik:GridTemplateColumn HeaderStyle-CssClass='GridHeaderGreen ra' ItemStyle-CssClass='ra' HeaderText="Error" UniqueName="ErrorMessageRecordCount">
            <ItemTemplate>
                <asp:HyperLink runat="server" ToolTip='<%# Eval("ErrorMessageRecordCount") %>' Text='<%# Eval("ErrorMessageRecordCount") %>'
                    NavigateUrl='<%# GetMessageDetailUrl(Container, ActLogSeverity.E) %>'>
                </asp:HyperLink>
            </ItemTemplate>
        </telerik:GridTemplateColumn>
    </Columns>

    I can't figure out, how to get current column index within GetMessageDetail method without these silly sending column number parameter, traversing some events, etc. I do have row number (container.ItemIndex), i do have column count total, but funny thing - i don't have column index! It's weird....
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Mar 2011 Link to this post

    Hello Alexander,

    The following code snippet shows how to get the column index.

    C#:
    public void GetMessageDetailUrl()
       {
           GridColumn column = (RadGrid1.MasterTableView.GetColumn("ErrorMessageRecordCount") as GridTemplateColumn);
            int orderIndex = column.OrderIndex-1;//getting column index
        }


    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Alexander
    Alexander avatar
    152 posts
    Member since:
    Jun 2012

    Posted 22 Mar 2011 Link to this post

    Hello. Thanks, but... :)
    but i meant how to determine current column if you DIDN'T know its unique name? ;) The only thing that is known, is that you are inside the specific grid column!

    So meaning pseudocode, i'd like to have something like Columns.CurrentColumn.OrderIndex :)
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 22 Mar 2011 Link to this post

    Hello Alexander,

    I guess there is no direct property available to find column index. One option is to loops through each column and get column index like below.

    C#:
    foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
       {
           if (col.UniqueName == "ErrorMessageRecordCount")
            {
                int orderIndex = column.OrderIndex - 1;
             }
        }

    Thanks,
    Princy.
Back to Top