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

Access a conrol outside grid from ItemCommand

6 Answers 140 Views
Grid
This is a migrated thread and some comments may be shown as answers.
rms
Top achievements
Rank 1
rms asked on 30 Apr 2012, 05:19 PM
Hi,

my requirement is to show list of values in a grid and when the user clicks on one of the columns, I have to display a radbutton. this button is on the page and is outside the grid
I am getting the commandname in the itemcommand event and trying to make radbutton visible.  button.visible=true. when i debug the code it looks like its working but the button is not diplayed. this button is invisible by default.
do i have to do a find control like i do for the controls inside the grid? if so what is the syntax for it?

Thanks.



6 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Apr 2012, 05:49 PM
Hello,

Please check below code snippet.

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" >
 
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    <telerik:AjaxUpdatedControl ControlID="Button1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

let me know if any concern.

Thanks,
Jayesh Goyani
0
rms
Top achievements
Rank 1
answered on 30 Apr 2012, 06:36 PM
That worked! thank you for a quick reply.
0
rms
Top achievements
Rank 1
answered on 02 May 2012, 08:24 PM
I have another Issue now. I think this is also related to the above thats why I am posting in the same thread.

I am trying to give a download functionality to the user on my page.

Response.ClearContent()

Response.ContentType =

 

"application/vnd.xls"

 

Response.AppendHeader(

 

"Content-Disposition", "attachment; filename=" & OnlyName)

 

Response.TransmitFile(filename)

Response.End()

the above code does not seem to work. this is on the same page where I have my Radgrid. What could be the work around for this?

Thanks

0
Accepted
Pavlina
Telerik team
answered on 07 May 2012, 01:53 PM
Hi,

The help article below describes how to download files with Ajaxified controls:
http://www.telerik.com/help/aspnet-ajax/ajax-download.html

Kind regards,
Pavlina
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.
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 07 May 2012, 06:44 PM
Hello,

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <ClientEvents OnRequestStart="onRequestStart" />
         
    </telerik:RadAjaxManager>
<script type="text/javascript">
        function onRequestStart(sender, args)
        {
            if (args.get_eventTarget().indexOf("lnkDownload") >= 0)
            {
                args.set_enableAjax(false);
            }
        }
    </script>
<MasterTableView DataKeyNames="ID" >
                <Columns>
                     
                    <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                    </telerik:GridBoundColumn>
                     
                    <telerik:GridTemplateColumn>
                        <ItemTemplate>
                            <asp:LinkButton ID="lnkDownload" runat="server" Text="Download sample excel file"
                                OnClick="lnkDownload_Click" CausesValidation="false"></asp:LinkButton>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
protected void lnkDownload_Click(object sender, EventArgs e)
        {
            // you can access your grid row
            Button lnkDownload = sender as Button;
            GridDataItem item = lnkDownload.NamingContainer as GridDataItem;
            string str1 = item.GetDataKeyValue("ID").ToString(); // by datakey ID
            string str2 = item["ID"].Text; // by column name
            try
            {
 
                string path = Server.MapPath("~/filepath/YourFilename.xlsx");
                string attachment = "attachment; filename=yourfilename.xlsx";
                Response.Clear();
                Response.AddHeader("content-disposition", attachment);
                Response.ContentType = "text/plain";
                Response.WriteFile(path);
                Response.End();
            }
            catch (Exception ex)
            {
                 
            }
        }


Thanks,
Jayesh Goyani
0
rms
Top achievements
Rank 1
answered on 08 May 2012, 03:32 PM
Both the solutions worked. Thank you Jayesh and Pavlina.
Tags
Grid
Asked by
rms
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
rms
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or