How do I get a reference to a button in a template column of my grid during PreRender?
Here is a grid (ShotDetail_RadGrid) that has tabs on each row of data. On the first of these tabs is another grid (Attachments_RadGrid) with the ImageButton I'm trying to get the reference to:
Here is my PreRender code. The viewImageButton is never set.
Thanks!
Here is a grid (ShotDetail_RadGrid) that has tabs on each row of data. On the first of these tabs is another grid (Attachments_RadGrid) with the ImageButton I'm trying to get the reference to:
<telerik:RadGrid ID="ShotDetail_RadGrid" runat="server" DataSourceID="ShotDetail_SqlDataSource" Skin="Black" GridLines="None" ShowStatusBar="True" Width="1100px" CellSpacing="0" AutoGenerateColumns="False"> <HierarchySettings ExpandTooltip="Show related merch" CollapseTooltip="Collapse merch"></HierarchySettings> <ExportSettings IgnorePaging="True"> <Pdf PageBottomMargin="0.5in" PageHeight="8.5in" PageLeftMargin="0.35in" PageRightMargin="0.35in" PageTopMargin="0.5in" PageWidth="11in" /> </ExportSettings> <ClientSettings> <Scrolling AllowScroll="True" UseStaticHeaders="True" /> </ClientSettings> <MasterTableView DataKeyNames="ShotID" DataSourceID="ShotDetail_SqlDataSource" AllowCustomPaging="True"> <NestedViewTemplate> <asp:Panel runat="server" ID="InnerContainer" CssClass="viewWrap" Visible="false"> <telerik:RadTabStrip runat="server" ID="TabStip1" MultiPageID="Multipage1" SelectedIndex="0"> <Tabs> <telerik:RadTab runat="server" Text="Merchandise" PageViewID="PageView1" Selected="True"> </telerik:RadTab> <telerik:RadTab runat="server" Text="Shot Support" PageViewID="PageView2"> </telerik:RadTab> <telerik:RadTab runat="server" Text="Completed Images"> </telerik:RadTab> </Tabs> </telerik:RadTabStrip> <telerik:RadMultiPage runat="server" ID="Multipage1" SelectedIndex="0" RenderSelectedPageOnly="false"> <telerik:RadPageView runat="server" ID="PageView1"> <asp:Label ID="ShotID_Label" Text='<%# Eval("ShotID") %>' Visible="false" runat="server" /> <asp:SqlDataSource ID="Merch_SqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:Alderman_ConnectionString %>" SelectCommand="sp_web_Merch_Grid_sel" SelectCommandType="StoredProcedure"> <SelectParameters> <asp:ControlParameter ControlID="ShotID_Label" PropertyName="Text" Type="Int32" Name="ShotID" /> </SelectParameters> </asp:SqlDataSource> <telerik:RadGrid ID="Merch_RadGrid" runat="server" AutoGenerateColumns="False" DataSourceID="Merch_SqlDataSource" GridLines="None" CellSpacing="0"> <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True"> </ClientSettings> <MasterTableView DataSourceID="Merch_SqlDataSource"> <CommandItemSettings ExportToPdfText="Export to Pdf" /> <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"> </RowIndicatorColumn> <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"> </ExpandCollapseColumn> <Columns> <telerik:GridBoundColumn DataField="Barcode" DataType="System.Int64" Display="False" HeaderText="Barcode" UniqueName="Barcode"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Source" HeaderText="Vendor" UniqueName="Source" FilterControlAltText="Filter Source column"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Description" HeaderText="Description" UniqueName="Description"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="SKU" HeaderText="SKU" UniqueName="SKU"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="SKU2" HeaderText="SKU2" UniqueName="SKU2"> </telerik:GridBoundColumn> </Columns> <EditFormSettings> <EditColumn FilterControlAltText="Filter EditCommandColumn column"> </EditColumn> </EditFormSettings> </MasterTableView> <FilterMenu EnableImageSprites="False"> </FilterMenu> <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default" EnableImageSprites="True"> </HeaderContextMenu> </telerik:RadGrid> </telerik:RadPageView> <telerik:RadPageView runat="server" Width="100%" ID="PageView2"> <asp:SqlDataSource ID="Attachments_SqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:Alderman_ConnectionString %>" SelectCommand="SELECT [AttachmentTitle], [LinkedFromID] FROM [tAttachments] WHERE (([LinkedFromID] = @ShotID) AND ([LinkedFromTable] = @LinkedFromTable) AND (AttachmentIsInvalid = 0))"> <SelectParameters> <asp:ControlParameter ControlID="ShotID_Label" PropertyName="Text" Type="Int32" Name="ShotID" /> <asp:Parameter DefaultValue="tShots" Name="LinkedFromTable" Type="String" /> </SelectParameters> </asp:SqlDataSource> <telerik:RadGrid ID="Attachments_RadGrid" runat="server" DataSourceID="Attachments_SqlDataSource" GridLines="None" CellSpacing="0"> <MasterTableView DataSourceID="Attachments_SqlDataSource" AutoGenerateColumns="False"> <CommandItemSettings ExportToPdfText="Export to PDF" /> <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"> </RowIndicatorColumn> <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"> </ExpandCollapseColumn> <Columns> <telerik:GridTemplateColumn UniqueName="ColumnDownload"> <ItemTemplate> <asp:ImageButton ID="DownloadForShot_ImageButton" runat="server" ImageUrl="~/Images/view.gif" OnClick="DownloadForShot_ImageButton_Click" /> <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridBoundColumn DataField="AttachmentTitle" HeaderText="Documents" UniqueName="ColumnAttachment"> </telerik:GridBoundColumn> </Columns> <EditFormSettings> <EditColumn FilterControlAltText="Filter EditCommandColumn column"> </EditColumn> </EditFormSettings> </MasterTableView> <FilterMenu EnableImageSprites="False"> </FilterMenu> <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"> </HeaderContextMenu> </telerik:RadGrid> </telerik:RadPageView> </telerik:RadMultiPage> </asp:Panel> </NestedViewTemplate> <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings> <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"> </RowIndicatorColumn> <ExpandCollapseColumn Visible="True"> </ExpandCollapseColumn> <Columns> <telerik:GridBoundColumn DataField="JobShot" HeaderText="Shot" UniqueName="JobShot"> <HeaderStyle Width="100px" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Description" HeaderText="Description" UniqueName="Description"> <HeaderStyle Width="700px" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="MerchCount" DataType="System.Int16" HeaderText="Merch Count" UniqueName="MerchCount" AllowFiltering="False"> <HeaderStyle Width="50px" /> <ItemStyle Wrap="True" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="JobNumber" Display="False" HeaderText="JobNumber" UniqueName="JobNumber" FilterControlAltText="Filter JobNumber column"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="ShotID" DataType="System.Int32" HeaderText="ShotID" UniqueName="ShotID" Display="False"> </telerik:GridBoundColumn> </Columns> <EditFormSettings> <EditColumn FilterControlAltText="Filter EditCommandColumn column"> </EditColumn> </EditFormSettings> <PagerStyle AlwaysVisible="True" /> </MasterTableView> <PagerStyle AlwaysVisible="True" /> <FilterMenu EnableImageSprites="False"> </FilterMenu> <HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Default"> </HeaderContextMenu></telerik:RadGrid>Here is my PreRender code. The viewImageButton is never set.
protected void ShotDetail_RadGrid_PreRender(object sender, EventArgs e){ if (!Page.IsPostBack) { //*** Associate each Attachments_RadGrid with its own postback script to open the file. for (int i = 0; i <= ShotDetail_RadGrid.MasterTableView.Items.Count - 1; i++) { Panel aspPanel = ShotDetail_RadGrid.MasterTableView.Items(i).ChildItem.FindControl("InnerContainer"); RadGrid attachmentsGrid = aspPanel.FindControl("Attachments_RadGrid"); RadScriptManager ScriptManager1 = default(RadScriptManager); ScriptManager1 = (RadScriptManager)this.Parent.FindControl("RadScriptManager1"); ScriptManager1.RegisterPostBackControl(attachmentsGrid); ImageButton viewImageButton = attachmentsGrid.MasterTableView.FindControl("DownloadForShot_ImageButton"); viewImageButton.Attributes.Add("onclick", " ExportButtonClick ();"); } }}Thanks!
