Welcome Guest Search | Active Topics | Sign In | Register

Grid checkbox click event Options
Saji
Posted: Friday, September 19, 2008 9:14:03 AM
Rank: Advanced Member
Groups: Member

Joined: 1/3/2008
Posts: 32
I have a grid, in that i have to add a checkbox column, when user clicks on the chckbox i have to track the click event, and store the Grid1.KeyField value to a textbox

this is the way i am adding the checkbox column

Dim dgCheckboxColumn As New EO.Web.CheckBoxColumn
dgRowNumColumn.Width = 30
dgRowNumColumn.AllowSort = True
Grid1.Columns.Add(dgCheckboxColumn)

please help me!!
eo_support
Posted: Friday, September 19, 2008 9:31:16 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,193
Hi,

The built-in CheckBoxColumn doesn't have any interface for you to be notified when the checkbox is checked or unchecked. So you won't be able to use that. Your best option would be using a StaticColumn with some HTML. You would need to:

1. Add a StaticColumn to the Grid;

2. Set the StaticColumn's DataField to some key data that you would like later use to identify the clicked item. For example, you can use the same value as KeyField, or you can use the item index. It is completely up to you to use whatever value here as soon as it works with other part of your code;

3. Set the StaticColumn's DataFormat to something like this:

Code: HTML/ASPX
<input type="checkbox" onclick="on_checkbox_clicked({0})" />


Note it passes {0} to on_checkbox_clicked handler. This is a JavaScript handler that you would need to provide. At runtime {0} is being replaced by value of your DataField. This is why step 2 is important;

4. You would then do whatever you would like to do in your on_checkbox_clicked handler. Please keep in mind this is a JavaScript handler. However you can raises a postback if you wish to do. The Grid provides raiseItemCommandEvent method that you may be able to use. You can also call the standard ASP.NET __doPostBack to raise server side event.

Hope this helps.

Thanks
Saji
Posted: Friday, September 19, 2008 10:52:46 PM
Rank: Advanced Member
Groups: Member

Joined: 1/3/2008
Posts: 32
Thanks for the support, the code is below


Dim dgStaticColumn As New EO.Web.StaticColumn
dgStaticColumn.AllowSort = True
dgStaticColumn.Width = 30
dgStaticColumn.DataField = ColumnName
dgStaticColumn.DataFormat = "<input type=""checkbox"" onclick=""on_checkbox_clicked(this, '{0}')""/>"
Grid1.Columns.Add(dgStaticColumn)

i have done in the above way..

function on_checkbox_clicked(objChkBox, pKey)
{
alert(pKey);
alert(objChkBox.checked);
}


its working perfectly, thank you for your support

Saji
Saji
Posted: Monday, September 22, 2008 6:56:09 AM
Rank: Advanced Member
Groups: Member

Joined: 1/3/2008
Posts: 32
I am able to track the click event using the above code, and able to store the selected row ids to table.

But now the next problem is, when i open the form next time I have to show some of the grid row selected (checked=true), basically previously selected rows, i have to show it as selected.

how it can be done ?

please help
eo_support
Posted: Monday, September 22, 2008 7:19:26 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,193
Hi Saji,

StaticColumn provides a generic way for you to generate HTML based on parameters from your data source. In your case, I would imagine you need to remember (or persist) what has been checked and then repopulate the Grid based on the new values. From the Grid point of view, it populates from a data source of whatever you give to it based on the DataFormat you provided. So anything beyond that --- in this case, how to remember/persist the data --- would have nothing to do with the Grid (thus also out of the scope of our support) and need to be solved separately.

Thanks
Saji
Posted: Tuesday, September 23, 2008 5:49:10 AM
Rank: Advanced Member
Groups: Member

Joined: 1/3/2008
Posts: 32
any way thanks for not supporting :-)

i have achieved it by using the following method: any body can use it.

Dim dgStaticColumn As New EO.Web.StaticColumn
dgStaticColumn.AllowSort = True
dgStaticColumn.Width = 30
dgStaticColumn.DataField = ColumnName
dgStaticColumn.DataFormat = "<input type=""checkbox"" id='{0}' onclick=""on_checkbox_clicked(this, '{0}')""/>"
Grid1.Columns.Add(dgStaticColumn)


function ShowChecked()
{
//alert(checkedValues.value);
for (var i=0; i<document.form1.elements.length; i++) {
var e = document.form1.elements[i];
//(e.name != 'allbox') &&
//&& (!e.disabled)
if ( (e.type=='checkbox') ) {
if (inSelectedList(e.id) == true)
e.checked = true;
else
e.checked = false;
}
}
}

function inSelectedList(Code)
{

var checkedValues;
checkedValues = document.getElementById("txtSelectedValues").value;
//alert(Code + ' ---- ' + checkedValues + ' >>>>>>>' + checkedValues.indexOf(Code));

if (checkedValues.indexOf(Code) == -1)
return false;
else
return true;


thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.