Hi all,
I have a couple of questions in regards to how to retrieve (get) the checkbox state value.
1. I have a an ultrawebgrid with three columns, col1 = Customer ID, col2 = Customer Name, col3=checkbox. (When the checkbox is clicked, it will determine wether an email will be sent out to this customer or not). The checkbox that I used is the one that comes with the webgrid. So all I did was create my column and set the Type="checkbox"
My webgrid has many rows and so from the webgrid and I would like to click on the check box for some customers (records) and not for some. Then I click the Save button to save (update the database) all of the records that have been checked. So on the code behind, how do I determine the value of the Customer ID, Customer Name and the checkboxes that have been selected on the Save button event? My Save button is a regular asp:Button (asp.net 2.0).
2. Would it be better to use an asp:checkbox and embedded inside the ultrawebgrid TemplateColumn?
Please let me know if option one is better or option two is better. Please provide some code sample if possible.
Thanks in advance!
hs2
Use the following code to get the checked columns:
foreach (UltraGridRow row in Grid.Rows)
{ if (row.Cells[columnIndex].Value.ToString().Equals("True")) { // CheckBox is checked }
else
{
// CheckBox is not checked.
} }
Hello Charuk,
I have tried to use the code you suggested above but it doesn't work. I loaded up my webgrid and click on the the checkbox and on the OnActiveCellChange event method and UpdateRowBatch event method, I tried determining the value of the check box but it returns False for the checked checkbox.
What event method did you try to above code on? This way I can use the same event method and try to see if it works and wether it would give me a True value when the checkbox is checked.
Thanks!
Hi hs2!
You said you want to determine the checked columns on the click of save. So try this code on the click event of the save button. I have also written this code on the click event of the button.
Regards,
Charuk
Hello Charuk.,
i copied and pasted your code into my Save button event method and tried it out, it still gives me the status of False even though the check box is checked. I even hardcoded the column name and columnindex just to test out but still doesn't work. Can you be more specific with the example like include the Save button click event and how you also add the checkbox column in the html side? I am not sure what I miss that it doesn't work.
THanks alot in advance!
HS2
I am setting the property ColumnType=CheckBox property of the UltraGridColum. I am doing everything by coding.... On button click m just takin da instance of the grid and writing dat code and it works fine for me.
How r u checking the checkbox? If u r doing it through code behind, then the checkbox values will not persist... you have to do it through javascript.
Plz give some code so that I can see if somthig is wrong....