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

find control in card view

2 Answers 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chom
Top achievements
Rank 1
Chom asked on 31 May 2011, 06:39 PM
Hello,

I am using the grid in card view and have data loading in the item template. I also have two link buttons in the template. Everything loads fine and pages OK. However I am trying to get to the click event of the link buttons so that when the user clicks on one of the link buttons I get a hidden field value which I use as a querystring parameter to take the user to a more detailed page.

I got it working on the first page but when I try to go to the next page in the grid. I get an error.

I am created a command name for the link butotns and have them in the grids Item_Command event. I am not sure if I am going about this the right way.

What am I doing wrong here?

<div style="margin-left: auto; margin-right: auto; margin-top: 50px; width: 800px">
    <telerik:RadGrid ID="RadGrid1" ShowGroupPanel="True" DataSourceID="SqlDataSource1"
        AllowPaging="True" runat="server" Width="800px" Height="800px" GridLines="None"
        PageSize="5" ShowHeader="false" BackColor="AliceBlue" BorderColor="Red" EnableEmbeddedSkins="true"
        Skin="Sitefinity">
        <HeaderContextMenu>
        </HeaderContextMenu>
        <MasterTableView TableLayout="Fixed">
            <ItemTemplate>
                <div style="float: left; margin-left: 10px; margin-top: 15px; width: 750px">
                    <div style="float: left; margin-bottom: 5px; font-size: 1.0em; font-weight: bold;
                        width: 700px">
                        <asp:LinkButton ID="lnkTitle" runat="server" ForeColor="Blue" CommandName="Title"
                            Font-Size="1.4em" Text='<%# Eval("Title")%>'>
                        </asp:LinkButton>
                        <asp:HiddenField ID="hdfId" runat="server" Value='<%# Eval("Id") %>' />
                    </div>
                    <br />
                    <div style="float: left; width: 98%; color: Green">
                        <%# Eval("City")%>,
                        <%# Eval("State")%>. - Posted:
                        <%# Eval("PostedDate")%></div>
                    <br />
                    <div style="float: left">
                        <%# Eval("Column1")%>
                        <div>
                            <asp:LinkButton ID="lnkMoreInfo" runat="server" CommandName="MoreInfo" ForeColor="Blue"
                                Text="more info..."></asp:LinkButton>
                        </div>
                    </div>
                </div>
            </ItemTemplate>
            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
            </RowIndicatorColumn>
            <EditFormSettings>
            </EditFormSettings>
            <AlternatingItemStyle BackColor="White" />
            <PagerStyle Mode="NextPrev" />
        </MasterTableView>
        <HeaderStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
            Font-Underline="False" Wrap="True" />
        <ClientSettings AllowDragToGroup="false">
            <Scrolling AllowScroll="true" UseStaticHeaders="true" />
        </ClientSettings>
        <FilterMenu EnableImageSprites="False">
        </FilterMenu>
    </telerik:RadGrid>
    <br />
    <br />
    <asp:Label ID="lblMsg" runat="server" ForeColor="Red" />
    <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
        SelectCommand="jobs_GridDataDisplay_Select" runat="server" SelectCommandType="StoredProcedure">
    </asp:SqlDataSource>

protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    //Find required controls in the grid.
    //Job Id.
    HiddenField hdfJobId = e.Item.FindControl("hdfId") as HiddenField;
    //Job title link button.
    LinkButton lnkTitle = e.Item.FindControl("lnkTitle") as LinkButton;
    //More info link button.
    LinkButton lnkMoreInfo = e.Item.FindControl("lnkMoreInfo") as LinkButton;
    if (lnkTitle.CommandName == "Title")
    {
        //Redirect to job details page.
        RedirectToJobDetails(hdfId.Value.ToString());
    }
    if (lnkMoreInfo.CommandName == "MoreInfo")
    {
        //Redirect to job details page.
        RedirectToJobDetails(hdfJobId.Value.ToString());
    }
}
private void RedirectToDetailsPage(string Id)
{
    //Redirection path.
    string url = "~/pages/content/details.aspx?";
    //Create the querystring parameter and encrypt.
    url += "id=" + Server.UrlEncode(DataEncryption.QueryStringEncrypt(Id));
    Response.Redirect(url);
}

2 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 06 Jun 2011, 09:21 AM
Hi Chom,

You did not mention what exactly the error is but I assume it comes from the fact that you are not checking the type of e.Item in the ItemCommand event. When it is fired by the grid pager, e.Item should be the pager itself and that is why you cannot access the controls in question. Try changing your logic, so that it checks the e.Item type before using it and let us know if the issue persists.

All the best,
Tsvetina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Chom
Top achievements
Rank 1
answered on 09 Jun 2011, 03:56 PM
I got it working. Thanks for the help.
Tags
Grid
Asked by
Chom
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Chom
Top achievements
Rank 1
Share this question
or