ListView checkbox error

  • Thread starter Thread starter David C
  • Start date Start date
D

David C

I am trying to set the OnCheckedChanged event on a control in a ListView
template and I am getting the error "The server tag is not well formed" but
I cannot figure out why. The error is occurring on the line with the
checkbox control. Below is the ItemTemplate. Can anyone help? I am trying
to run a subroutine and send it a value from the TransID data item. Thanks.

David

<ItemTemplate>
<tr style="background-color:#DCDCDC;color: #000000;">
<td><asp:LinkButton ID="LBtnEdit" runat="server"
CommandName="Edit" Text="Edit"></asp:LinkButton></td>
<td><asp:CheckBox ID="ckPayTrans" runat="server"
Checked='<%# Eval("PayTrans") %>' AutoPostBack="True"
OnCheckedChanged="Check_Clicked(<%# Eval("TransID") %>)" /></td>
<td><asp:Label ID="LblTransDate" runat="server" Text='<%#
Eval("TransDate", "{0:d}") %>' /></td>
<td><asp:Label ID="LblClient" runat="server" Text='<%#
Eval("ClientLastFirst") %>' /></td>
<td><asp:Label ID="LblExpense" runat="server" Text='<%#
Eval("Expense") %>' />
<asp:Label ID="LblIncomeType" runat="server" Text='<%#
Eval("IncomeType") %>' CssClass="Hide" />
</td>
<td><asp:Label ID="LblVendorName" runat="server" Text='<%#
Eval("VendorName") %>' /></td>
<td align="right"><asp:Label ID="LblTransAmount"
runat="server" Text='<%# Eval("TransAmount", "{0:n2}") %>' /></td>
<td><asp:Label ID="LblAccountNo" runat="server" Text='<%#
Eval("AccountNo") %>' /></td>
<td><asp:Label ID="LblReferenceNo" runat="server" Text='<%#
Eval("ReferenceNo") %>' /></td>
<td><asp:LinkButton ID="LBtnDelete" runat="server"
CommandName="Delete" Text="Delete" CssClass="Hide"
OnClientClick="return confirmDel('Inc/Exp
Transaction');"></asp:LinkButton></td>
</tr>
</ItemTemplate>
 
I am trying to set the OnCheckedChanged event on a control in a ListView
template and I am getting the error "The server tag is not well formed" but
I cannot figure out why.  The error is occurring on the line with the
checkbox control. Below is the ItemTemplate.  Can anyone help?  I am trying
to run a subroutine and send it a value from the TransID data item.  Thanks.

David

        <ItemTemplate>
            <tr style="background-color:#DCDCDC;color: #000000;">
                <td><asp:LinkButton ID="LBtnEdit" runat="server"
CommandName="Edit" Text="Edit"></asp:LinkButton></td>
                <td><asp:CheckBox ID="ckPayTrans" runat="server"
Checked='<%# Eval("PayTrans") %>' AutoPostBack="True"
OnCheckedChanged="Check_Clicked(<%# Eval("TransID") %>)" /></td>
                <td><asp:Label ID="LblTransDate" runat="server" Text='<%#
Eval("TransDate", "{0:d}") %>' /></td>
                <td><asp:Label ID="LblClient" runat="server" Text='<%#
Eval("ClientLastFirst") %>' /></td>
                <td><asp:Label ID="LblExpense" runat="server" Text='<%#
Eval("Expense") %>' />
                    <asp:Label ID="LblIncomeType" runat="server" Text='<%#
Eval("IncomeType") %>' CssClass="Hide" />
                </td>
                <td><asp:Label ID="LblVendorName" runat="server" Text='<%#
Eval("VendorName") %>' /></td>
                <td align="right"><asp:Label ID="LblTransAmount"
runat="server" Text='<%# Eval("TransAmount", "{0:n2}") %>' /></td>
                <td><asp:Label ID="LblAccountNo" runat="server" Text='<%#
Eval("AccountNo") %>' /></td>
                <td><asp:Label ID="LblReferenceNo" runat="server" Text='<%#
Eval("ReferenceNo") %>' /></td>
                <td><asp:LinkButton ID="LBtnDelete" runat="server"
CommandName="Delete" Text="Delete" CssClass="Hide"
                        OnClientClick="return confirmDel('Inc/Exp
Transaction');"></asp:LinkButton></td>
           </tr>
        </ItemTemplate>

Look at the line with

OnCheckedChanged="Check_Clicked(<%# Eval("TransID") %>)" />

You need to replace quotes like it was done with Checked='<%# Eval
("PayTrans") %>'
 
I am trying to set the OnCheckedChanged event on a control in a ListView
template and I am getting the error "The server tag is not well formed"
but
I cannot figure out why. The error is occurring on the line with the
checkbox control. Below is the ItemTemplate. Can anyone help? I am trying
to run a subroutine and send it a value from the TransID data item.
Thanks.

David

<ItemTemplate>
<tr style="background-color:#DCDCDC;color: #000000;">
<td><asp:LinkButton ID="LBtnEdit" runat="server"
CommandName="Edit" Text="Edit"></asp:LinkButton></td>
<td><asp:CheckBox ID="ckPayTrans" runat="server"
Checked='<%# Eval("PayTrans") %>' AutoPostBack="True"
OnCheckedChanged="Check_Clicked(<%# Eval("TransID") %>)" /></td>
<td><asp:Label ID="LblTransDate" runat="server" Text='<%#
Eval("TransDate", "{0:d}") %>' /></td>
<td><asp:Label ID="LblClient" runat="server" Text='<%#
Eval("ClientLastFirst") %>' /></td>
<td><asp:Label ID="LblExpense" runat="server" Text='<%#
Eval("Expense") %>' />
<asp:Label ID="LblIncomeType" runat="server" Text='<%#
Eval("IncomeType") %>' CssClass="Hide" />
</td>
<td><asp:Label ID="LblVendorName" runat="server" Text='<%#
Eval("VendorName") %>' /></td>
<td align="right"><asp:Label ID="LblTransAmount"
runat="server" Text='<%# Eval("TransAmount", "{0:n2}") %>' /></td>
<td><asp:Label ID="LblAccountNo" runat="server" Text='<%#
Eval("AccountNo") %>' /></td>
<td><asp:Label ID="LblReferenceNo" runat="server" Text='<%#
Eval("ReferenceNo") %>' /></td>
<td><asp:LinkButton ID="LBtnDelete" runat="server"
CommandName="Delete" Text="Delete" CssClass="Hide"
OnClientClick="return confirmDel('Inc/Exp
Transaction');"></asp:LinkButton></td>
</tr>
</ItemTemplate>

Look at the line with

OnCheckedChanged="Check_Clicked(<%# Eval("TransID") %>)" />

You need to replace quotes like it was done with Checked='<%# Eval
("PayTrans") %>'

Do you mean like this?

OnCheckedChanged='Check_Clicked(<%# Eval("TransID") %>)'

I tried and now I am getting the error "BC30456: '__DataBinding__control13'
is not a member of 'ASP.checkinfo_incexpentry_aspx'"

David
 
Look at the line with

OnCheckedChanged="Check_Clicked(<%# Eval("TransID") %>)" />

You need to replace quotes like it was done with Checked='<%# Eval
("PayTrans") %>'

Do you mean like this?

OnCheckedChanged='Check_Clicked(<%# Eval("TransID") %>)'

I tried and now I am getting the error "BC30456: '__DataBinding__control13'
is not a member of 'ASP.checkinfo_incexpentry_aspx'"

David- Hide quoted text -

- Show quoted text -

Sorry, I didn't pay attention to the code you have inside '...'

You need to move Check_Clicked inside <%# ... %> tags

OnCheckedChanged='<%# Check_Clicked(Eval("TransID")) %>'
 
Look at the line with

OnCheckedChanged="Check_Clicked(<%# Eval("TransID") %>)" />

You need to replace quotes like it was done with Checked='<%# Eval
("PayTrans") %>'

Do you mean like this?

OnCheckedChanged='Check_Clicked(<%# Eval("TransID") %>)'

I tried and now I am getting the error "BC30456:
'__DataBinding__control13'
is not a member of 'ASP.checkinfo_incexpentry_aspx'"

David- Hide quoted text -

- Show quoted text -

Sorry, I didn't pay attention to the code you have inside '...'

You need to move Check_Clicked inside <%# ... %> tags

OnCheckedChanged='<%# Check_Clicked(Eval("TransID")) %>'


I tried your suggestion and now I get a compilation error below.

BC30518: Overload resolution failed because no accessible 'ToString' can be
called with these arguments:
 
Sorry, I didn't pay attention to the code you have inside '...'

You need to move Check_Clicked inside <%# ... %>  tags

OnCheckedChanged='<%# Check_Clicked(Eval("TransID")) %>'

I tried your suggestion and now I get a compilation error below.

BC30518: Overload resolution failed because no accessible 'ToString' can be
called with these arguments:- Hide quoted text -

- Show quoted text -

On what line? I see no 'ToString' property in your code.
 
Sorry, I didn't pay attention to the code you have inside '...'

You need to move Check_Clicked inside <%# ... %> tags

OnCheckedChanged='<%# Check_Clicked(Eval("TransID")) %>'

I tried your suggestion and now I get a compilation error below.

BC30518: Overload resolution failed because no accessible 'ToString' can
be
called with these arguments:- Hide quoted text -

- Show quoted text -

On what line? I see no 'ToString' property in your code.

On the same line of the CheckBox control. If I remove the OnCheckChanged
portion then I get no error. The runtime error is showing this whole line
in red so something is causing it but i cannot figure out what. I included
the code for the Sub being called but it really doesn't have much in it yet,
I am just trying to get it to work.

Sub Check_Clicked(ByVal intTransID As Int32)

Dim tb As TextBox = Page.Master.FindControl("txtMsg")

tb.Text = "TransID sent = "

End Sub
 
On what line? I see no 'ToString' property in your code.

On the same line of the CheckBox control. If I remove the OnCheckChanged
portion then I get no error. The runtime error is showing this whole line
in red so something is causing it but i cannot figure out what. I included
the code for the Sub being called but it really doesn't have much in it yet,
I am just trying to get it to work.

Sub Check_Clicked(ByVal intTransID As Int32)

Dim tb As TextBox = Page.Master.FindControl("txtMsg")

tb.Text = "TransID sent = "

End Sub- Hide quoted text -

- Show quoted text -

Hi David,

Ok, I see what the problem is. You get an error because The event
handler must be matched the OnCheckedChanged event delegate signature.
The OnCheckedChanged event uses the EventHandler class for the
delegate type and the EventArgs class for the event data.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkbox.oncheckedchanged.aspx

This means that you need to have Check_Clicked in the following way:

Protected Sub Check_Clicked(ByVal sender As Object, ByVal e As
EventArgs)

Dim tb As TextBox = ...

' Gets the CheckBox object that fired the event.
Dim chkBox As CheckBox = CType(sender, CheckBox)

' Gets the item that contains the CheckBox object.
Dim item As ListViewDataItem = CType(chkBox.Parent.Parent,
ListViewDataItem)

' Replace ListView1 with ID of your ListView Control
tb.Text = "TransID sent = " & ListView1.DataKeys
(item.DataItemIndex).Value

End Sub

This should give you a text "TransID sent = XXX" if check box has been
changed. Note, that I was using ListView1.DataKeys property, this
means that if you didn't specify DataKeys for your ListView control
you need to add it as well

<asp:ListView ... DataKeyNames="TransID">

Hope this helps
 
Alexey Smirnov said:
Hi David,

Ok, I see what the problem is. You get an error because The event
handler must be matched the OnCheckedChanged event delegate signature.
The OnCheckedChanged event uses the EventHandler class for the
delegate type and the EventArgs class for the event data.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkbox.oncheckedchanged.aspx

This means that you need to have Check_Clicked in the following way:

Protected Sub Check_Clicked(ByVal sender As Object, ByVal e As
EventArgs)

Dim tb As TextBox = ...

' Gets the CheckBox object that fired the event.
Dim chkBox As CheckBox = CType(sender, CheckBox)

' Gets the item that contains the CheckBox object.
Dim item As ListViewDataItem = CType(chkBox.Parent.Parent,
ListViewDataItem)

' Replace ListView1 with ID of your ListView Control
tb.Text = "TransID sent = " & ListView1.DataKeys
(item.DataItemIndex).Value

End Sub

This should give you a text "TransID sent = XXX" if check box has been
changed. Note, that I was using ListView1.DataKeys property, this
means that if you didn't specify DataKeys for your ListView control
you need to add it as well

<asp:ListView ... DataKeyNames="TransID">

Hope this helps

Thank you for your patience.
It worked, but I had to remove one of the extra .parent references in the
ListViewDataitem.

David
 
Thank you for your patience.
It worked, but I had to remove one of the extra .parent references in the
ListViewDataitem.

David- Hide quoted text -

- Show quoted text -

It's great that it works now!
 
Back
Top