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

Button in column to open radWindow

3 Answers 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Declan
Top achievements
Rank 2
Declan asked on 04 Nov 2008, 06:39 PM

I am using a radGrid for Customer Orders. To each order I can attach uploaded files. Because I was having difficulties with radUpload and Ajax I decided to do the uploading using a radWindow.

Two pieces of information are required to attach the uploaded documents to the Order; CustomerID and OrderID.

I assign the CustomerID to a hidden field in the ItemDataBound event of the grid.

The grid uses GridTemplateColumn with teh "form fields" laid out in this single column. A second GridTemplateColum is used for the button to attach files:

<telerik:GridTemplateColumn UniqueName="GridTemplateColumn" HeaderText="GridTemplateColumn">  
    <ItemTemplate>  
        <button id="btnShowDlg" onclick="showDialog();return false;" type="submit">Click here to attach files</button>   
    </ItemTemplate>  
</telerik:GridTemplateColumn> 

RadWindow manager is used to open a window passing the CustomerID as an argument from the hidden field. This works fine.

Where I run into trouble is trying to get the OrderID from the grid row on which the button was clicked. I have tried various methods using Javascript found on this site without success.

Using OnClick on the button allows me open the window and pass the CustomerID as an argument but I just can't figure out how to get the OrderID from the row whose button was clicked.

All suggestions welcome.

Declan
 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 05 Nov 2008, 05:57 AM
Hello Declan,

You can try the following code to achieve the required scenario.
aspx:
<telerik:GridTemplateColumn UniqueName="GridTemplateColumn" HeaderText="GridTemplateColumn"
     <ItemTemplate>                
         <input runat="server" id="Submit1" type="submit" value="Click here to attach files"  /> 
     </ItemTemplate> 
</telerik:GridTemplateColumn> 

cs:
 protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
      if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            string strtxt = item["CustomerID"].Text; 
            string strtxt2=item["OrderID"].Text; 
            HtmlInputSubmit btn = (HtmlInputSubmit)item["GridTemplateColumn"].FindControl("Submit1"); 
            btn.Attributes.Add("onclick", "return ShowDialog('" + strtxt + "','" + strtxt2 + "');");          
            
        } 
    } 

js:
function  ShowDialog(CustomerID,OrderID) 
 {     
    var Wnd = radopen("Default.aspx?Customer ID=" + CustomerID+ "& Order ID=" +OrderID, "RadWindow1" ); 
   return false; 
 } 

Thanks
Princy.
0
Declan
Top achievements
Rank 2
answered on 05 Nov 2008, 02:56 PM
Hi Princy,

Thanks, that works a treat :)

One minor problem:- I don't seem to be able to reference the upload.aspx.

All I can get to work is the full path to the file within the application. This is part of a DotNetNuke module but I don't think that is relevant.

var Wnd = window.radopen("/dnn4/DesktopModules/testUpload/Upload.aspx?CUID=" + CustomerID + "&ORID=" + OrderID, "RadWindow1");  
 

Folder structure

dnn4
-    bin
-    DesktopModules
- -        testUpload

While this allows the app to work it means having to change the ascx when moving to production. It would be nice if I could get a relative reference to work. What have I missed?

Thanks,
Declan

0
Declan
Top achievements
Rank 2
answered on 10 Nov 2008, 03:14 PM
Solution:

Dim btn As HtmlInputSubmit = DirectCast(item("GridTemplateColumn").FindControl("Submit1"), HtmlInputSubmit)  
 
Dim sFileToOpen As String = ResolveUrl("Upload.aspx") & "/Upload.aspx" 
Dim sAttributes As String 
 
sAttributes = "return ShowUpload('" + sFileToOpen + "','" + strtxt + "','" + strtxt2 + "');" 
btn.Attributes.Add("onclick", sAttributes) 

Thanks.
Tags
Grid
Asked by
Declan
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Declan
Top achievements
Rank 2
Share this question
or