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

[Solved] Grid ClientSelect column

2 Answers 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ayesha
Top achievements
Rank 1
Ayesha asked on 20 Jul 2009, 02:40 AM
Hi,

I've a gridclientselct column in radgrid as one column. I need to put a alert message(in js) telling theuser to select atleast one row. I cannot allow the user to save (save button
) without select one row in radgrid. how do i do this. I'm using this in ascx with c#. Kindly let me know how to do this.
Thanks,
ZR

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Jul 2009, 05:49 AM
Hi Zaheka,

Give a try with the following approach to achieve the desired scenario.

ASCX:
 
 <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Save" OnClientClick="return AlertMessage();"  /> 

JS:
 
<script type="text/javascript" > 
 
 function AlertMessage() 
 { 
  var MasterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView(); 
  var selectedRows = MasterTable.get_selectedItems(); 
  if(selectedRows.length==0) 
  { 
      alert('You have not selected any rows in the Grid.Make sure that You select atleast One row'); 
      return false
  } 
 } 
 
</script> 


Hope this helps..
Shinu.
0
Ayesha
Top achievements
Rank 1
answered on 21 Jul 2009, 04:56 PM

Hi,

To implement the alert message if user does not selct a row in the grid , I did the following lines in my ascx page

<

 

head>

 

<

 

title></title>

 

<

 

script type="text/javascript">

 

 

function SelectRowAlertMessage()

 

{

 

 

var MasterTable = $find("<%=ctlRecipientsGrid.ClientID%>").get_masterTableView();

 

 

var selectedRows = MasterTable.get_selectedItems()[0];

 

 

 

if (selectedRows.length == 0) {

 

alert(

'You have not selected any rows in the Grid.Make sure that You select atleast One row');

 

 

return false;

 

}

}

</

 

script>

 

</

 

head>

where ctlRecipientsGrid is my gridname.

and 

 

<

 

asp:Button ID="btnOK" runat="server" Text="OK"

 

 

Width="79px" onclick="btnOK_Click" OnClientClick="return SelectRowAlertMessage();"/>

If i did this and try to run my project , i get this
"Microsoft JScript runtime error: Object expected".

why do i get this ?? Am i missing out something.
NOTE: this is done in usercontrols page .ascx.

Pls do reply.
Thanks,
ZR

 

Tags
Grid
Asked by
Ayesha
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ayesha
Top achievements
Rank 1
Share this question
or