I found the solution in case anyone was wondering. I changed the htmlanchor to
an asp:hyperlink and then changed the button event to this.
private void buttonContactNotFound_Click(object sender, System.EventArgs e)
{
//footer control count is -2 if paging is used, otherwise it's -1
DataGridItem dataGridItem =
(DataGridItem)dataGridContacts.Controls[0].Controls[dataGridContacts.Controls[0].Controls.Count-2];
((HyperLink)dataGridItem.FindControl("hyperLinkAddContactSearch")).Visible =
false;
((LinkButton)dataGridItem.FindControl("linkButtonContactAddNew")).Visible =
true;
}
Jim
yalwho <[EMAIL PROTECTED]> wrote:
Maybe this will simplify the issue.
I had a teamamte try and help and this seemed like it should work. I
changed my button event handler to loop through the datagrid items
looking for the footer item. But when stepping through in debug I
noticed that the loop only sees the item and alternating item types.
How do I get into the footer item to grab this hyperlink and set
it's visibility to true? The grid displays fine and now I don't get
the error as before, but the hyperlink is not found either.
private void buttonContactNotFound_Click(object sender,
System.EventArgs e)
{
foreach(DataGridItem dataGridItem in dataGridContacts.Items)
{
if(dataGridItem.ItemType == ListItemType.Footer)
{
((HtmlAnchor)dataGridItem.FindControl
("hyperLinkAddContactSearch")).Visible = false;
((LinkButton)dataGridItem.FindControl
("linkButtonContactAddNew")).Visible = true;
}
}
}
--- In [email protected], "yalwho" <[EMAIL PROTECTED]>
wrote:
>
> I have a datagrid with an edit column and a footer with an add
> hyperlink(hyperLinkAddContactSearch) in the edit column. The add
> link displays a div that has a button(buttonContactNotFound) in it
> that upon clicking should hide the footer link
> (hyperLinkAddContactSearch) in the edit column and make visible a
> different link button(linkButtonContactAddNew) in the same cell in
> the footer. I have not been successful at referencing either of
the
> links in the footer edit column. I
> get "System.NullReferenceException: Object reference not set to an
> instance of an object." error message when trying to access the
> visible properties of the links in the datagrid. I have tried a
> couple of datagrid.findcontrol methods and I couldn;t get that to
> work either. Maybe I am missing the event that is getting fired
when
> the (buttonContactNotFound) button is getting clicked.
>
> Any thoughts or tips or work arounds??
>
> Here's my partial datagrid showing the edit column.
>
> <asp:datagrid id="dataGridContacts" runat="server" Width="700px"
> AutoGenerateColumns="False" ShowFooter="True">
> <Columns>
> <asp:TemplateColumn Visible="False"
> HeaderText="ContactID">
> <ItemTemplate>
> <asp:Label runat="server"
ID="labelContactID"
> Text='<%# DataBinder.Eval(Container, "DataItem.ContactID") %>'>
> </asp:Label>
> </ItemTemplate>
> </asp:TemplateColumn>
> <asp:TemplateColumn HeaderText="Edit">
> <ItemTemplate>
> <asp:LinkButton runat="server" Text="Edit"
> CausesValidation="false" ID="linkButtonContactEdit"
> CommandName="Edit"
> CommandArgument="{0}"
> OnCommand="linkButtonContactEdit_Click"></asp:LinkButton>
> </ItemTemplate>
> <FooterTemplate>
> <a href="#" ID="hyperLinkAddContactSearch"
> onclick="hyperLinkAddContactSearch_Click();">
> Add</a>
> <asp:LinkButton Visible="False"
runat="server"
> Text="Insert" CausesValidation="false" ID="linkButtonContactAddNew"
> CommandName="AddNew"
> OnCommand="linkButtonContactAddNew_Click"></asp:LinkButton>
> </FooterTemplate>
> <EditItemTemplate>
> <asp:LinkButton runat="server" Text="Update"
> CausesValidation="false" ID="linkButtonContactUpdate"
> CommandName="Update" CommandArgument='<%# DataBinder.Eval
> (Container, "DataItem.ContactID") %>'
> OnCommand="linkButtonContactUpdate_Click">
> </asp:LinkButton>
> <asp:LinkButton runat="server" Text="Delete"
> CausesValidation="false" ID="linkButtonContactDelete"
> CommandName="Delete" CommandArgument='<%# DataBinder.Eval
> (Container, "DataItem.ContactID") %>'
> OnCommand="linkButtonContactDelete_Click">
> </asp:LinkButton>
> <asp:LinkButton runat="server" Text="Cancel"
> CausesValidation="false" ID="linkButtonContactCancel"
> CommandName="Cancel"
> OnCommand="linkButtonContactCancel_Click"></asp:LinkButton>
> </EditItemTemplate>
> </asp:TemplateColumn>
>
> Here's the div with the button.
>
> <div id="divContactSearch" style="DISPLAY: none;POSITION:
> absolute" runat="server">
> <TABLE id="tableContactSearch" height="100"
cellSpacing="0"
> cellPadding="3" width="300">
> <TR id="tableRowContactSearchHeader">
> <TD><asp:label id="labelContactSearch"
> runat="server">Contact Search</asp:label></TD>
> <TD></TD>
> </TR>
> <TR id="tableRowContactSearchItem">
> <TD><asp:dropdownlist id="dropDownListSearchContacts"
> runat="server"></asp:dropdownlist></TD>
> <TD><asp:button id="buttonContactAddExisting"
> runat="server" Text="Add"></asp:button></TD>
> </TR>
> <TR id="tableRowContactSearchItem2">
> <TD>
> <TD><asp:button id="buttonContactNotFound"
> runat="server" Text="Not Found"></asp:button></TD>
> </TR>
> <TR id="tableRowContactSearchFooter">
> <TD></TD>
> <TD><A onclick="divHide('divContactSearch')"
> href="#">Cancel</A></TD>
> </TR>
> </TABLE>
> </div>
>
> Here's my event handler for the button to try and hide and show
the
> links.
>
> private void buttonContactNotFound_Click(object sender,
> System.EventArgs e)
> {
> hyperLinkAddContactSearch.Visible = false;
> linkButtonContactAddNew.Visible = true;
> }
>
> Thanks,
> Jim
>
SPONSORED LINKS
Basic programming language Computer programming languages
Programming languages Java programming language
---------------------------------
YAHOO! GROUPS LINKS
Visit your group "AspNetAnyQuestionIsOk" on the web.
To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
---------------------------------
---------------------------------
Yahoo! Personals
Skip the bars and set-ups and start using Yahoo! Personals for free
[Non-text portions of this message have been removed]
------------------------ Yahoo! Groups Sponsor --------------------~-->
Most low income households are not online. Help bridge the digital divide today!
http://us.click.yahoo.com/I258zB/QnQLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/