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

Using Grid, Fire ItemCommand after RadWindow

2 Answers 193 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Casey
Top achievements
Rank 1
Casey asked on 23 Apr 2009, 12:01 AM
So, I've been digging though the forums, looking for a solution, and havent found one yet. There might be a better solution for what I'm doing, and if there is, let me know. Otherwise, here goes.

I'm using the RadGrid from the RadControls Q3 2008. This grid lists the status of some items, and has two linkbuttons "Approve", and "Deny". In either case, when one of those buttons is clicked a RadWindow pops-up, and prompts the user to enter in a reason for the approve, or the deny. Problem is, when the rad-window closes, the ItemCommand event for the Grid never fires. The ItemCommand method is where my logic for persisting it to the database goes. How do I get this event to fire? I'm using the ItemCreated method to create the OnClientClick method. This brings me to another issue. I want to send the value of one of the GridCells to the RadWindow, I figure I'll modify the URL in the case as it's passed to the radwindow. ?id=14 for instance. I need to code that in the OnClientClick, but I dont think the Gird has those values yet. Here is the code I have:

The JavaScript on the main page:
    <telerik:RadCodeBlock ID="RCB" runat="server">  
        <script type="text/javascript">  
            function ShowInsertForm(rowNum)  
            {  
                window.radopen("approvalcomments.aspx?id=" + rowNum + ""null);  
                //window.radopen(null, "radWindowComments");  
                return false;  
            }  
              
            function OnClientClose(radwindow)  
            {  
                if (radwindow != undefined) {  
                    var oValue = radwindow.argument;  
                    //alert(oValue);  
                    alert("I Fired");  
                    ///return true;  
                    var aplhie = '<% = Label1.ClientID %>';  
                    var lbl = document.getElementById(aplhie);  
                    lbl.innerHTML = "If I could, I would update that row you just clicked on, adding the comments: " + oValue;  
                }    
            }  
        </script>  
    </telerik:RadCodeBlock> 

The grid on the main page:
        <telerik:RadGrid ID="grid_Approval" runat="server" TabIndex="5"   
            Skin="Office2007" AllowMultiRowSelection="True" AllowSorting="True"   
            DataSourceID="oDataSource" GridLines="None" OnItemCommand="grid_Approval_ItemCommand" OnItemCreated="grid_Approval_ItemCreated" Ena >   
<HeaderContextMenu> 
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
</HeaderContextMenu> 
 
<MasterTableView DataSourceID="oDataSource" autogeneratecolumns="False">  
    <Columns> 
        <telerik:GridButtonColumn  
            CommandName="Approve" 
            Text="Approve" 
            UniqueName="Approve">  
        </telerik:GridButtonColumn> 
        <telerik:GridButtonColumn  
            CommandName="Deny" 
            Text="Deny" 
            UniqueName="Deny">  
        </telerik:GridButtonColumn> 
        <telerik:GridBoundColumn DataField="ID" HeaderText="ID"   
            SortExpression="ID" UniqueName="ID">  
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="EMP_ID" HeaderText="EMP_ID"   
            SortExpression="EMP_ID" UniqueName="EMP_ID">  
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="ADDRESS" HeaderText="ADDRESS"   
            SortExpression="ADDRESS" UniqueName="ADDRESS">  
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="JOB_NUMBER" HeaderText="JOB_NUMBER"   
            SortExpression="JOB_NUMBER" UniqueName="JOB_NUMBER">  
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="JUSTIFICATION" HeaderText="JUSTIFICATION"   
            SortExpression="JUSTIFICATION" UniqueName="JUSTIFICATION">  
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="AMOUNT" DataType="System.Decimal"   
            HeaderText="AMOUNT" SortExpression="AMOUNT" UniqueName="AMOUNT">  
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="PC" HeaderText="PC" SortExpression="PC"   
            UniqueName="PC">  
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="AWARD_NAME" HeaderText="AWARD_NAME"   
            SortExpression="AWARD_NAME" UniqueName="AWARD_NAME">  
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="CREATOR" HeaderText="CREATOR"   
            SortExpression="CREATOR" UniqueName="CREATOR">  
        </telerik:GridBoundColumn> 
    </Columns> 
</MasterTableView> 
 
<FilterMenu> 
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
</FilterMenu> 
        </telerik:RadGrid> 


The .cs for the main page:
    protected void grid_Approval_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)  
    {  
        string theCmd = e.CommandName.ToString();  
        if (theCmd == "Deny")  
        {  
            Label1.Text = "You are going to deny item " + e.Item.Cells[4].Text;  
        }  
        if (theCmd == "Approve")  
        {  
            Label1.Text = "You are going to approve item " + e.Item.Cells[4].Text;  
 
        }  
    }  
 
    protected void grid_Approval_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
        if (e.Item is Telerik.Web.UI.GridDataItem)  
        {  
            Telerik.Web.UI.GridDataItem dataItem = e.Item as Telerik.Web.UI.GridDataItem;  
            LinkButton button = dataItem["Approve"].Controls[0] as LinkButton;  
 
            Label1.Text = e.Item.RowIndex.ToString();  
            button.OnClientClick = String.Format("return ShowInsertForm();");  
            button.Attributes["href"] = "#";  
        }  
    } 

Ideas?
Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 27 Apr 2009, 05:33 AM
Hi Casey,

Try the fireCommand() method which triggers specific command for the grid when executed. The method is called for the GridTableView client instance and its arguments depend on the command which will be processed. See the following example.

[aspx]
 
<telerik:RadWindowManager ID="RadWindowManager1" runat="server"
/telerik:RadWindowManager> 

[javascrip]
 
<script type="text/javascript">    
function ShowInsertForm(rowNum)    
{    
    var oWnd = window.radopen("Align.aspx?id=" + rowNum + ""null);    
    oWnd.add_close(OnClientClose);  
}    
function OnClientClose()    
{  
    FireCommand();      
}    
function FireCommand()  
{  
  var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();  
  masterTable.fireCommand("MyCommand","args");  
}   
</script>   

[cs]
 
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    if (e.CommandName == "MyCommand"
    { 
         // Do your logic here  
         // e.CommandArgument is the argument passed  
    } 

Thanks,
Shinu.
0
Casey
Top achievements
Rank 1
answered on 28 Apr 2009, 10:25 PM
Ha! That did exactly what I wanted it to do. Thanks!
Tags
Grid
Asked by
Casey
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Casey
Top achievements
Rank 1
Share this question
or