Friday, September 26, 2014

Access RadGrid on Client using Javascript/Jquery

To access RadGrid on client, use following code.
I will also show the code that doesn't work:

 
// didnt work. .Net crash saying The Controls collection cannot be modified because the control contains code blocks (i.e. <%--<% %>--%>)
<%--var grid1 = $find("<%= RadGrid1.ClientID%>");--%>

//didnt work. This just gives Null.   
<%--var grid1 = $find("<%# RadGrid1.ClientID%>"); --%> 

//didnt work. This just gives Null.  
<%--var grid1 = document.getElementById('<%# RadGrid1.ClientID%>') --%> 

//didnt work. It give me ID of RadGrid; not a reference to object.  
var grid1 = document.getElementById('RadGrid1').id;  

//This gives reference as htmldiv control which still cant be used to access functions of radgrid.  
var grid1 = document.getElementById('RadGrid1')

  
// THIS WORKS **********************************************
  
var grid = $find(document.getElementById("RadGrid1").id);

var masterTable = grid.get_masterTableView();
  
//********************************************
  

Thursday, September 25, 2014

Add js reference in aspx page

Hello All,

While working on some js code, I couldn't figure out that why my function declared in js external file not being fired from LinkButton.
I had reference inside head tags which was WRONG.
The reference need to be inside <body> under <form> tag.

<body>
<form id="form1" runat="server">       
<script type="text/javascript" src="scripts/grid.js" ></script>
.
.
.
.

Tuesday, September 23, 2014

Insert Variable along with data in SQL

Create a table with some data in it:
       

create table #data (name varchar(500))
insert into #data (name)
select 'Texas'
union 
select 'LA'
union 
select 'Kansas'
union 
select 'New York'

-- Create Dest Table 
create table #dest (id int, name varchar(500))

-- Select the code below to insert into #dest table 
declare @vid int
set @vid = 1 <-- Any value 

insert into #dest (id, name)
select @vid, s.name from 
(select name from #data) s 
------------------------------------------------------

insert into #dest (id, name)
select @vid , (select top 10 name from #data) <-- This will give subquery return more than 1 row error message 


 

Monday, September 22, 2014

Javascript breakpoint VS 2013

In VS 2013, there is a bug that wont let debugger to stop at the breakpoint.

The workaround is to add "debugger" keyword in js code before the line of breakpoint and then debugger will stop / hit the breakpoint.

Here is the MS connect solution

HTH

Wednesday, September 10, 2014

How to read data from RadGrid?

Hello,

While working on RadGrid, I was in need of real data bind to Grid. I was able to access text of GridViewItem using (gridItem("col1").Text) but if text is formatted, then only you can see is the formatted data.

To see the exact data bind to Grid, use the DataItem property as shown below:

Private Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles RadGrid1.ItemDataBound

    Dim gridItem As GridDataItem = CType(e.Item, GridDataItem)
    Dim data as String = DirectCast(gridItem.DataItem, System.Data.DataRowView).Row.ItemArray(0)

End Sub


HTH