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

Trying to access TextBox in a RadGrind and pass it to RadWindow

2 Answers 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prithvi
Top achievements
Rank 1
Prithvi asked on 31 Jan 2011, 03:49 PM
Hi,

I am trying to access the text box in a radgrid and pass the values of the selected row in the grid with the new value in the textbox to a radwindow which is opened when a button in the same row is clicked. 

I am using the following code

aspx:
function ShowDispatchNote(rowIndex, MediaID, ReferenceText) {
                var grid = $find("<%= rgBookoutMedia.ClientID %>");
                var firstDataItem = $find("<%=rgBookoutMedia.ClientID %>").get_masterTableView().get_dataItems()[rowIndex];
                var MediaID = firstDataItem.getDataKeyValue("MediaID");
                var masterTable = grid.get_masterTableView();
                for (var i = 0; i < masterTable.get_dataItems().length; i++) {
                    // to access the textbox in each row 
                    var txtbx = masterTable.get_dataItems()[i].findElement("rtbReference");
                    // set alert 
                }
                window.radopen("DispatchNote.aspx?MediaID=" + MediaID + "&ReferenceText=" + txtbx.Text, "RadWindow1");
                return false;
            }


cs:
if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = rgBookoutMedia.NamingContainer as GridDataItem;
                Button btnConfirm = (Button)e.Item.FindControl("btnConfirm");
                RadTextBox rtbReference = (RadTextBox)e.Item.FindControl("rtbReference");
                btnConfirm.Attributes["onclick"] = String.Format("return ShowDispatchNote('{0}','{1}');", e.Item.ItemIndex, e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["MediaID"], rtbReference.Text);
            }

I am able to get the value of MediaID as I have specified it as DataKeyNames in the MasterTableView. The other query string ReferenceText shows up as undefined always. How do I get the value of the textbox with new values in the client side before opening the rad window.

The example in http://www.telerik.com/community/code-library/aspnet-ajax/grid/accessing-server-controls-in-a-grid-template-on-the-client.aspx doesn't satisfy my criteria. Can anyone show me a code sample on how to pass the new textbox value to the radwindow.

Thanks
Prithvi

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 01 Feb 2011, 06:54 AM
Hello Prithvi,

Make the following modification in your code and check whether it works now.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem dataItem = (GridDataItem)e.Item;
           Button btnConfirm = (Button)e.Item.FindControl("btnConfirm");
           RadTextBox rtbReference = (RadTextBox)e.Item.FindControl("rtbReference");
           btnConfirm.Attributes["onclick"] = String.Format("return ShowDispatchNote('{0}');", e.Item.ItemIndex);
       }
   }

Java Script:
<script type="text/javascript">
     function ShowDispatchNote(rowIndex) {
         var grid = $find("<%=rgBookoutMedia.ClientID %>");
        var firstDataItem = grid.get_masterTableView().get_dataItems()[rowIndex];
        var MediaID = firstDataItem.getDataKeyValue("MediaID");
        var masterTable = grid.get_masterTableView();
        var txtbx = firstDataItem.findControl("rtbReference").get_value();// getting TextBox vaue
         window.radopen("DispatchNote.aspx?MediaID=" + MediaID + "&ReferenceText=" + txtbx , "RadWindow1");
        return false;
    }
</script>

Thanks,
Princy.
0
Prithvi
Top achievements
Rank 1
answered on 02 Feb 2011, 05:41 PM
Hi Princy,

That worked. Thanks.

Prithvi
Tags
Grid
Asked by
Prithvi
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Prithvi
Top achievements
Rank 1
Share this question
or