Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <body>
- <div id="grid1" style="width: 100%; height: 150px;"></div>
- <script type="text/javascript">
- $(function () {
- w2utils.settings.RESTfull = true
- $('#grid1').w2grid(
- {
- name: 'grid1',
- contentType: "application/json;charset=utf-8",
- method: 'Get',
- dataType: "jsonp",
- url: 'data/Default2.aspx/DatasetToString',
- columns: [
- {id:'recid', field: 'recid', caption: 'recid', size: '50px' },
- {
- id:'stuid', field: 'stuid', caption: 'stuid', size: '30%'
- },
- { id:'stuname',field: 'stuname', caption: 'stuname', size: '30%' },
- ],
- records: [ ],
- onLoad: function (target, data) {
- var response = [];
- response = data.xhr.responseText.match(/{.*(.*)}/);
- var final = response[0];
- var s =JSON.parse(final);
- w2ui.grid1.total = w2ui.grid1.records.length;
- w2ui.grid1.records.push(final);
- console.log(final);
- data.preventDefault();
- this.refresh();
- }
- });
- });
- </script>
- </body>
- </html>`
- protected void Page_Load(object sender, EventArgs e)
- {
- data();
- DatasetToString(ds);
- }
- public DataSet data()
- {
- SqlCommand cmd = new SqlCommand("JSONProcas2", con);
- var x = cmd.CommandType = CommandType.StoredProcedure;
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- da.Fill(ds,"jj");
- return ds;
- }
- public String DatasetToString(DataSet ds)
- {
- int i = 0;
- String str = "";
- DataTable dt = ds.Tables[0];
- while (i < dt.Rows.Count)
- {
- str += dt.Rows[i][0].ToString();
- i++;
- }
- Response.Write(str);
- return (str);
- }
- }
- create procedure [dbo].[JSONProcas2]
- as
- begin
- select '{"status":"success"'+
- ',"records":[' + STUFF((
- select
- ',{"recid":' + cast(recid as varchar(max))
- +',"stuid":' + cast(stuid as varchar(max))
- + ',"stuname":"' + stuname + '"'
- +'}'
- from student2 t1
- for xml path(''), type
- ).value('.', 'varchar(max)'), 1, 1, '') + ']}'
- end
- {"status":"success","records":[{"recid":1,"stuid":100,"stuname":"lavanya"},{"recid":2,"stuid":101,"stuname":"kk"}]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement