最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - Get the values of a cell in a selected row of a RadGrid on client Side - Stack Overflow

programmeradmin0浏览0评论

Hey there everyone, I'm hoping there is a simple fix for this, but I would accept a plicated one after messing around with it for the last day and a half!

I am putting together a module that will drop into a DotNetNuke portal and I'm populating a Telerik RadGrid with data. I have followed every tutorial and example I can find, but the result keeps ing back with "object Object", "null", or "undefined".

I need to: 1) get the value of the "BookingID'" column for each row that is selected 2) pass the value into a url string that opens up in a RadWindow.

I'm trying to do all of this using javascript, but if you know a better way, I'm down for anything at this point.

Here is my current JavaScript and a stripped down radGrid:

 ///Javascript///

function gup(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null) return "";
    else return results[1];
}
    function ShowEditForm() {
        var tab = gup('tabid')
        var mid = gup('mid').replace(/#/, '')
        var masterTableView = $find("perDiemBookingsRadGrid").get_masterTableView();
        var id = masterTableView.get_selectedItems()[0].getDataKeyValue('BookingID');

        window.radopen("/Default.aspx?tabid=" + tab + "&ctl=multiEdit&mid=" + mid + "&SkinSrc=[G]Skins/Blue-NCPP/Plain&BIDs=" + id, "RadWindow3");
    }

Hey there everyone, I'm hoping there is a simple fix for this, but I would accept a plicated one after messing around with it for the last day and a half!

I am putting together a module that will drop into a DotNetNuke portal and I'm populating a Telerik RadGrid with data. I have followed every tutorial and example I can find, but the result keeps ing back with "object Object", "null", or "undefined".

I need to: 1) get the value of the "BookingID'" column for each row that is selected 2) pass the value into a url string that opens up in a RadWindow.

I'm trying to do all of this using javascript, but if you know a better way, I'm down for anything at this point.

Here is my current JavaScript and a stripped down radGrid:

 ///Javascript///

function gup(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null) return "";
    else return results[1];
}
    function ShowEditForm() {
        var tab = gup('tabid')
        var mid = gup('mid').replace(/#/, '')
        var masterTableView = $find("perDiemBookingsRadGrid").get_masterTableView();
        var id = masterTableView.get_selectedItems()[0].getDataKeyValue('BookingID');

        window.radopen("/Default.aspx?tabid=" + tab + "&ctl=multiEdit&mid=" + mid + "&SkinSrc=[G]Skins/Blue-NCPP/Plain&BIDs=" + id, "RadWindow3");
    }
Share Improve this question asked Jun 23, 2010 at 16:25 cmmitwcmmitw 31 gold badge1 silver badge5 bronze badges 2
  • It won't let me post my grid because it has images...I'll clean it up and post in a few minutes. – cmmitw Commented Jun 23, 2010 at 16:26
  • Nevermind, it just doesn't like my grid for some reason. how about this way? senduit./acafd4 – cmmitw Commented Jun 23, 2010 at 16:33
Add a ment  | 

2 Answers 2

Reset to default 2

The following code will get you the key for the selected row. Normally, I do not pop-up RadWindow when user selects row. I let them click on an Image/button to pop-up RadWindow.

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
 <!--
    function RowSelected(sender, args)
    {
      var userId = args.getDataKeyValue("UserId");
      window.radopen('UserDetail.aspx?userid=' + userId, "RadWindow1");
    }   
    -->
</script>
</telerik:RadCodeBlock>
<telerik:RadGrid ID="RadGrid1" runat="server" >
  <MasterTableView ClientDataKeyNames="UserId" />
     <ClientSettings>
        <Selecting AllowRowSelect="true" />
        <ClientEvents OnRowSelected="RowSelected" />
        </ClientSettings>
  </telerik:RadGrid>

<%-- RadWindowManager --%>
<telerik:RadWindowManager ID="RadWindowManager1" runat="server" Modal="true" Behaviors="Default"
 VisibleTitlebar="true" VisibleStatusbar="false" InitialBehavior="Reload" Style="z-index: 7001"
  Skin="Default" DestroyOnClose="true" Width="750px" Height="500px" >
   <windows>
  <telerik:RadWindow ID="RadWindow1" runat="server">
    </telerik:RadWindow>
  </windows>
</telerik:RadWindowManager>
var grid = $find("<%=perDiemBookingsRadGrid.ClientID%>")

Then you can loop through the rows in grid.MasterTableView.SelectedRows and get the values

for(var i = 0; i < grid.MasterTableView.SelectedRows.length; i++)
{
    var selectedRow = grid.MasterTableView.SelectedRows[i];
    var id = selectedRow.KeyValues["BookingID"];
    //code to do stuff here.
}
发布评论

评论列表(0)

  1. 暂无评论