Datagrid/checkbox hell...

S

Stu Lock

Hi,

I have a data grid with a checkbox column in it bound to database.
(IsItNumeric return either True/False).

<asp:TemplateColumn HeaderText="In List">
<ItemTemplate>
<asp:CheckBox id="InList" runat="server"
OnCheckedChanged="PersistToDB" Checked='<%#
IsItNumeric(DataBinder.Eval(Container, "DataItem.InList")) %>'
AutoPostBack="True">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

This works fine. However, when a user changes the state of a particular
checkbox I handle the postback event 'PersistToDB'. I can get the checked
state of the checkbox that has just been chaged, but I cannot get the
'DataKey' of the row. I have been trying:

iMyVal = dgResult.DataKeys.Item(CType(sender, DataGridItem).ItemIndex)

I get the error 'Specified cast not allowed etc...'. Is there any way to get
the DataKey of the item that has changed (rather than looping and checking
the state of every single checkbox in the grid) ?

Thanks in advance,

Stu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top