I'm not able to find controls in an EditItemTemplate. I have a datalist which is bound on Not IsPostBack, and it has an item template simply displaying a list of vendors. When i click on the Edit LinkButton, my EditItemTemplate is loaded with a form to change info about that vendor. I load the form fine and can populate the fields how i want to. however i also want to have checkboxes (only one here for simplicity) which show hidden parts of the form that update more advanced portions.
Here is my Datalist definition:
<asp:DataList id="dtlLinks" runat="server" OnEditCommand="dtlLinks_Ed
itCommand"
OnUpdateCommand="dtlLinks_
UpdateComm
and" OnCancelCommand="dtlLinks_
CancelComm
and" OnDeleteCommand="dtlLinks_
DeleteComm
and" DataKeyField="VendorID">
<ItemTemplate>
<asp:LinkButton Text="Edit" CommandName="edit" runat="server" ID="lnkEdit" NAME="lnkEdit" /> -
<%# Container.DataItem("Vendor
Name") %>
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox id="chkChangeLinkImage" runat="server" Text="Change?" AutoPostBack="True"
OnCheckedChanged="ShowHide
Panel" />
<asp:Panel id="pnlNewLinkImage" runat="server" Visible="False">
<asp:TextBox id="txtInPanel" runat="server" Text="You Made It!" />
</asp:Panel>
<asp:LinkButton id="lnkUpdate" Text="Update" CommandName="update" runat="server" />
<asp:LinkButton id="lnkCancel" Text="Cancel" CommandName="cancel" runat="server" />
<asp:LinkButton id="lnkDelete" Text="Delete" CommandName="delete" runat="server" />
</EditItemTemplate>
</asp:DataList>
Now what i want to happen is when chkChangeLinkImage is checked, i want to show the hidden panel. My Code behind (selections) looks like:
===
Page_Load
===
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.PageTitle = "SamplePage.aspx"
If Not IsPostBack Then
BindList()
End If
End Sub
===
===
Sub dtLinks_EditCommand
===
Sub dtlLinks_EditCommand(ByVal
s As Object, ByVal e As DataListCommandEventArgs) Handles dtlLinks.EditCommand
dtlLinks.EditItemIndex = e.Item.ItemIndex
BindList()
End Sub
===
===
Sub ShowHidePanel - Called when checkbox is checked
===
Sub showHidePanel(ByVal s As Object, ByVal e As System.EventArgs) Handles chkChageLinkImage.CheckedC
hanged
Dim pnl As Panel
Dim chk As CheckBox
Try
chk = CType(FindControl("chkChan
geLinkImag
e"), CheckBox)
pnl = CType(FindControl("pnlNewL
inkImage")
, Panel)
Response.Write("ctype ID = " & CType(FindControl("pnlNewL
inkImage")
, Panel).ID)
Catch exp As NullReferenceException
Response.Write("it messed up: e = " & exp.Message)
End Try
End Sub
===
I can't find controls. I always get thrown into the NullReferenceException. How/Where Do i find these controls so i can make this work?? Leave any questions that you may need about my code or just ask for other parts as i will be checking this very frequently
Thank you