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
Hi Colette
I am new to dotnet, could you please mention the code for initialising webgrid in page load(), does that mean setting the webgrid.datasource to null or the code which we write in initialisedatasource event?
ThankYou in advance
Hi,
I am facing the same issue. And I do not even have problem with re-binding grid on each postback.
But the thing is, I have a webgrid in user control and this user control is getting loaded dynamically on aspx page.
If I postback the page after checking / unchecking every checkbox, the state of checkbox is retained. But if there is no postback after every cell update in webgrid, on final "save" click, checkbox state always shows "Checked = false" even though on the screen, checkboxes are seen chekced.
Any guesses, why checkbox looses the stae?
Thanks & Regards,
Rasika.
Hello Colette,
Thanks so much!! It worked! I can't believe that was all I missed!
Take care and happy coding!!
Hi HS2,
In the Page_Load method of your page do you have the code for initialising the webgrid surrounded with an if(!Page.IsPostback) block?
If you don't have this block around the webgrid databinding then the grid will be reset when you click the Save button.
Colette
Hi Charuk,
Yep, I tried that the case you suggested above already. But still doesn't work. It seems like it doesn't know that my checkbox even exist. I have no idea why and that's why it keeps on return false. I wish the Infragistic experts would give me an example of exactly how to use checkbox on the server side. I want to be able to get the checkbox state on the server side so I can update the database so that way it use a service to send out email to customers. I think I might have a post a new question in order to get their attention. I see alot of people having problem with checkboxes. Alot of people are posting the same sort of question as me but getting no answer.
Thanks Charuk for all of your help. I really appreciate that!!! If you see anything or have any suggestion, I would love to if you can forward it to.