Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Please help me with paramters passing to asp.net for id
18/09/2013
05:33
Avatar
jqgrealynasty
Member
Members
Forum Posts: 8
Member Since:
18/09/2013
sp_UserOfflineSmall Offline

A jqgrid uses below js script as sample and default.aspx page which display the grid using C# code. js Script:

jQuery(document).ready(function(){
jQuery("#htmlTable5").jqGrid({ url:'Default2.aspx?cmd=select', mtype: 'GET',
 datatype: 'json',
colNames:['ID','Make'],
colModel :[{
name:'id'
,index:'id'
,width:40
,jsonmap:'id'
},{
name:'Make'
,index:'Make'
,align:'left'
,width:60
,jsonmap:'Make'
}],
pager:
jQuery('#htmlPager5'),
rowNum:10,
height: "100%",
rowList:[10,20,30],
sortname: 'id',
sortorder: "asc",
viewrecords: true,
reloadAfterSubmit: true,
editurl:'Default2.aspx?cmd=delete',
onSelectRow: function (id) {
var selr = jQuery('#htmlTable5').jqGrid('getGridParam', 'selrow');
alert('Selected row ID ' + id);
if (id == null) {
id = 0;
que = 1; if (jQuery('#htmlTable5').jqGrid('getGridParam', 'id') > 0) {
jQuery('#htmlTable5').jqGrid('setGridParam', { url: 'Default.aspx?cmd=select&que=0&
id=' + id,
mytype: 'GET',datatype: 'json' });
jQuery('#htmlTable5').jqGrid('setCaption', "Image Detail: " + id)
.trigger('reloadGrid'); }
} else {
jQuery('#htmlTable5').jqGrid('setGridParam', { url: 'Default.aspx?cmd=select&
que=1&id=' + id,
mytype: 'GET', datatype: 'json'});
jQuery('#htmlTable5').jqGrid('setCaption', "Image Detail: " + id)
.trigger('reloadGrid');
}
},
}).navGrid('#htmlPager5',{edit:false,add:false,del:true,search:true,refresh:true});

My Question/Need: I need badly please the feature that when I click to select a row on the grid,

the id field of selected row will be

retrieved in Default.aspx.cs code file so that it printed in a text box on the Default.aspx page.

I could view the grid data but when I click on a row on the grid it does identify the id (which I want)

but I cannot retrieve it on the back code of the page (Default.aspx.cs) as a parameter,

Default.aspx.cs use the following to reload the grid:


if (Request.QueryString["cmd"] == "select")
it is detected and run the grid but adding


if (Request.QueryString["cmd"] == "delete")
or

if (Request.QueryString["cmd"] == "que")
it is always null.

There is must be something wrong with the request. Can anybody help please on this issue? I'll be very

appreciated.

Tried setting:

jQuery('#htmlTable5').jqGrid('setGridParam', { url: 'Default.aspx?cmd=select&que=1&id=' + id,

mytype: 'POST', datatype: 'json'});

But it does not work (I see it inside diagnosing tool like firebug is exist as que 1 but

on page_load it is always null no matter what statement I use. Please I need your help..

18/09/2013
11:51
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

It is difficult to me to read your post.

Can you please write it a gain?

Just the description - I see the code.

Kind Regards

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

18/09/2013
20:35
Avatar
jqgrealynasty
Member
Members
Forum Posts: 8
Member Since:
18/09/2013
sp_UserOfflineSmall Offline

Thank you Tony for the msg. Here I rewrite what the issue is: When I click to select a row on the jqgrid it does

not send the selected row id field. In other word, for some reason that I cannot retrieve the id on the backend

C# code of the page that displays the grid.

Using Resquest.QueryString["id"] / Resquest.QueryString["que"] per my posted code above is always null, tried

to use post/get methods and still I cannot retrieve the id of selected row, even though I could see the grid

respond to my selection by showing the selected row id on the Caption of the grid, in addition that I could

trace using firebug utility that a response with parameters showing

que=1 and id=x.

Some info about the grid: the grid uses above JS code on the header of Default.aspx page

and Resquest.QueryString["id"] / Resquest.QueryString["que"] is used in the Page_Load section code of

same page (Default.aspx.cs).

I do not know why cmd=select would work to display the grid content but nothing else of other parameters,

how to pass a parameter

from the grid then to the page to be used like showing a picture of the selected row on the grid??

Is there a filter on the grid??? Is it suppose to be editurl to direct the response to a different page???

But why select parameter would work?? I'm really confused and tired of this issue. I appreciate any

hint or guide.Yell By the way why when posting on this forum the text are cliped from the most right side?

19/09/2013
12:04
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Sorry, but I can not tell you why is this.

I'm not familiar with ASP C#and etc.

For me the there are some unsual thing.

1. When the row is selected you set new url and reload the grid. This will happen every time a row is selected.

Why do you not use this url by default.

2. You can use only one url and use postData to send a parameters to the server.

jqGrid('setGridParam', { postData: { id:id, ...}});

The simple test case for me is

in a onSelectRow event do not use any grid code - just pur ajax and try to obtain the id like this

onSelectRow : function (id) {

   $.ajax({

      url: "Default.....?id="+id,

      success : function(response) {...}

...

   }

}

and see if the parameter is send.

I hope you got the point.

Kind Regards,

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

19/09/2013
21:57
Avatar
jqgrealynasty
Member
Members
Forum Posts: 8
Member Since:
18/09/2013
sp_UserOfflineSmall Offline

tony Hello,

Following your suggestion:

onSelectRow: function (id) {
//var treedata = $("#htmlTable5").jqGrid('getRowData', id);
var selr = jQuery('#htmlTable5').jqGrid('getGridParam', 'selrow');
//var value = $('#htmlTable5').jqGrid('getCell', sel_id, '_id');
//alert('Selected row ID ' + id);
id = selr;
$("#htmlTable5").jqGrid('setGridParam', {postData: {id:id}, mtype: 'POST'});
$.ajax({
url: 'GetData.aspx?cmd=select&que=1&search=false&rows=10&page=1&sidx=id&sord=asc&id=' + id,
success : function(response) {
                
                }
                });

I could see same results but I simply could not detect if id is actually sent and not null

I use the following on the Page_load function to detect if id is not null then a label on

the same page should displaythe selected id like (I do see and veriy through Firebug

utility the parameters of id is set correctly after selection and  exists):

 if (Request["id"] != null)
            {
                ltl2.Text = "Selecting: " + Request.QueryString["id"];
            }

OR

if (Request.QueryString["id"] != null)
            ltl2.Text = "Sel = " + Request.QueryString["id"].ToString();

but nothing on the page.Frown I tried to use Global variable on the web site and set it with the

selected id and when I refresh the page I do see the result on the page, this means, it does

detect posted id but how to force grid to refresh the entire page to show the result?? may

I send you to your email the testing code?? I appreciate your kind help.

20/09/2013
07:19
Avatar
12seconds
Member
Members
Forum Posts: 6
Member Since:
20/09/2013
sp_UserOfflineSmall Offline

Hi,

Is your javascript doing a post back when you select a field on the jqgrid? So the link will be something similar:

localhost:port/Default.aspx?cmd=select&que=0&id=123

Where 123 is the ID selected in the jqgrid.

If that link is displaying and working correctly then you can use querystring on your pageload:

if(!IsPostBack) 

{

if(Page.Request.QueryString["id"] != string.Empty || Page.Request.QueryString["id"] != null)

{

ltl2.Text = "Selecting: " + Page.Request.QueryString["id"].ToString();

}

My suggestion for you is to make a hidden field and pass the ID to that hidden field.

That way it won't cause post back every time you make a selection...

20/09/2013
07:47
Avatar
jqgrealynasty
Member
Members
Forum Posts: 8
Member Since:
18/09/2013
sp_UserOfflineSmall Offline

12seconds said:

Hi,

Is your javascript doing a post back when you select a field on the jqgrid? So the link will be something similar:

localhost:port/Default.aspx?cmd=select&que=0&id=123

Where 123 is the ID selected in the jqgrid.

If you talk about the url address on the webpage of the browser on top. No. It shows only the

name of the page "like localhost/website/Default5.aspx", I feel that JqGrid does not refresh

entire page, I have setup Firbug (A utility shows what actually posted by the script to the

page) When I first load the grid I get on the param section the following:

http://localhost/webpage/Defau.....e&nd=

1379651648678&rows=10&page=1&sidx=id&sord=asc' (This does not show on the

browser URL as I stated)

and paramtered shown that suppose to be posted:

_search

false
cmd

select
nd

1379651648678
page

1
que

1
rows

10
sidx

id
sord

asc

While if I click on a field on the grid data (Say row with id 17) I get the following paramters shown:

cmd

select
id

17
page

1
que

1
rows

10
search

false
sidx

id
sord

asc

If that link is displaying and working correctly then you can use querystring on your pageload:

if(!IsPostBack) 

{

if(Page.Request.QueryString["id"] != string.Empty || Page.Request.QueryString["id"] != null)

{

ltl2.Text = "Selecting: " + Page.Request.QueryString["id"].ToString();

}

My suggestion for you is to make a hidden field and pass the ID to that hidden field.

That way it won't cause post back every time you make a selection...

I have made a hidden field but the value of id is always null, I tried in desperate of thinking

why, I made the call to a different page when I do select row in the onselectrow property

and I made a Global variable on the website so that all pages see it and I have on the

calling/main page setting the value of the id to a asp label and the label does not

have the id posted only when I click icon of reload the entire page. I wish if I could

send the testing webpage to someone  to understand what I mean and test it.



20/09/2013
08:00
Avatar
12seconds
Member
Members
Forum Posts: 6
Member Since:
20/09/2013
sp_UserOfflineSmall Offline

Hi, 

If your url is only = "localhost/website/Default5.aspx"... You cannot use Request.QueryString to retrieve the id...

May I ask how you did your hidden field? 

But anywho here's a snippet how you would do a hidden field:

<asp:HiddenField ID="hfjqGridID" runat="server" />


On Javascript:

var val = document.getElementById('<%= hfjqGridID.ClientID %>');  

val.value = id;

//Add this line to test out if your ID is being passed in correctly.

alert(val.value);

Once you have that you can see if your server side can read the value on PageLoad

if(!isPostBack)
{

Response.Write(hfjqGridID.Value);

Cheers



20/09/2013
09:04
Avatar
jqgrealynasty
Member
Members
Forum Posts: 8
Member Since:
18/09/2013
sp_UserOfflineSmall Offline

Yes, at all cases on the link only show "localhost/website/Default5.aspx" and I do not know how

the paramters for the grid are passed and retrieved by Response.QueryString like select, row, sord, sidx

of what the jqgrid needs to make response back of Json data format for the grid while adding id

and que parameters are not detected.  I might did Not know how to use the hidden field, please can you

give me more details on it?? I did not understand your JS part, how to assign the selected row id

to the hidden field within onSelectedRow property? The grid does interact and get the id on selection

but what is :

hfjqGridID.ClientID
all what I want is on selection I display an image related to that selected row on the same page.

I see the grid when I select a row/field it does not refresh or initiate postback on the page so
how when you write into the response stream the value of hidden field how to get the that value
back????
Response.Write(hfjqGridID.Value);????
21/09/2013
01:54
Avatar
12seconds
Member
Members
Forum Posts: 6
Member Since:
20/09/2013
sp_UserOfflineSmall Offline

Hi,
Right, Reponse.Write cannot be used since no postback is done...

Since jqgrid doesn't postback to the server.. One option is to use ajax with code handler, or web service.

As for the javascript,

Whenever onSelectRow is called in jqgrid you assigned the ID to the hiddenfield. You don't have to use HiddenField, if you dont know about them you can just use a label and hide it.

However, if you do want to learn more about HiddenField, I suggest you to have a look into MSDN Library.
http://msdn.microsoft.com/en-u.....&nbsp;

21/09/2013
06:39
Avatar
jqgrealynasty
Member
Members
Forum Posts: 8
Member Since:
18/09/2013
sp_UserOfflineSmall Offline

Please can you give me more details, I'm a novice in web techs, is it like what Tony said on his first post for ajax:

onSelectRow : function (id) {

   $.ajax({

      url: "Default…..?id="+id,

      success : function(response) {…}

   }

}

which method is the more reliable and simpler ajax or web service, and can you please give me an example or some guide?

21/09/2013
09:33
Avatar
12seconds
Member
Members
Forum Posts: 6
Member Since:
20/09/2013
sp_UserOfflineSmall Offline

Spent 20 mins on this so... Ill keep it simple.
I am using ajax with handler approach rather than using ajax and webservice which you can do to achieve the same result. 

HTML

<body>
<form id="form1" runat="server">     
<div>      
<table id="grid"></table>        
<asp:Label ID="lblID" runat="server"></asp:Label>
</div>
</form> 
</body> 

JAVASCRIPT Below Body 

<script>
var data = [[1, "Hello"], [2, "World"]];
$("#grid").jqGrid({
datatype: "local",
height: 250,
colNames: ['ID', 'Name'],
colModel: [{
name: 'id',
index: 'id',
width: 60,
sorttype: "int"},
{name: 'name',
index: 'name',
width: 90,
sorttype: "string"}],
caption: "example",
viewrecords: 'true',
onSelectRow: function (id) {
var IDLabel = document.getElementById('<%= lblID.ClientID %>');
$.ajax({
url: "Handler.ashx?id=" + id,
success: function (result) {
IDLabel.innerHTML= result;
}
});
},
});
var names = ["id", "name"];
var mydata = [];
for (var i = 0; i < data.length; i++) {
mydata[i] = {};
for (var j = 0; j < data[i].length; j++) {
mydata[i][names[j]] = data[i][j];
}
}
for (var i = 0; i <= mydata.length; i++) {
$("#grid").jqGrid('addRowData', i + 1, mydata[i]);
}
</script>

ASHX Hander.ashx

<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;

public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string id = "";
if (context.Request.QueryString["id"] != null)
{
id = (context.Request.QueryString["id"]).ToString();
}
context.Response.Write(id);
}

public bool IsReusable { get { return false; } }
}

That's it! Label text should change based on your row ID

Cheers

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
44 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information