CodeVerge.Net Beta


   Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums



Zone: > Asp.Net Forum > asp.net_ajax.asp.net_ajax_ui Tags:
Item Type: Date Entered: 1/8/2008 3:39:27 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
8.50
XPoints: N/A Replies: 8 Views: 3169 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
9 Items, 1 Pages |< << Go >> >|
"SunfireGFX" <>
NewsGroup User
FindControl in Listview9/28/2007 12:31:44 AM

1

hey everyone i need help with the findcontrol for the listview control, i want to accsess a textbox in the insertitem template,

i used this code to get but it returned

Object reference not set to an instance of an object.

the code:

protected void Page_Load(object sender, EventArgs e)

{

 

((
TextBox)ListView1.FindControl("TaxFileIDTextBox")).Text = Profile.TaxfileID;

}

<asp:listview ID="ListView1" runat="server"

DataKeyNames="ID,TaxFileID,FiscalYearID" DataSourceID="LandExpolitation"

InsertItemPosition="LastItem">

<alternatingitemtemplate>

<tr runat="server" style="">

<td>

<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"

Text="Delete" />

<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />

</td>

<td>

<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />

</td>

<td>

<asp:Label ID="TaxFileIDLabel" runat="server"

Text='<%# Eval("TaxFileID") %>' />

</td>

<td>

<asp:Label ID="FiscalYearIDLabel" runat="server"

Text='<%# Eval("FiscalYearID") %>' />

</td>

<td>

<asp:Label ID="LandDimensionsLabel" runat="server"

Text='<%# Eval("LandDimensions") %>' />

</td>

<td>

<asp:Label ID="RentalValueLabel" runat="server"

Text='<%# Eval("RentalValue") %>' />

</td>

<td>

<asp:Label ID="LandLocationLabel" runat="server"

Text='<%# Eval("LandLocation") %>' />

</td>

</tr>

</alternatingitemtemplate>

<edititemtemplate>

<tr runat="server" style="">

<td>

<asp:Button ID="UpdateButton" runat="server" CommandName="Update"

Text="Update" />

<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"

Text="Cancel" />

</td>

<td>

<asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />

</td>

<td>

<asp:Label ID="TaxFileIDLabel1" runat="server"

Text='<%# Eval("TaxFileID") %>' />

</td>

<td>

<asp:Label ID="FiscalYearIDLabel1" runat="server"

Text='<%# Eval("FiscalYearID") %>' />

</td>

<td>

<asp:TextBox ID="LandDimensionsTextBox" runat="server"

Text='<%# Bind("LandDimensions") %>' />

</td>

<td>

<asp:TextBox ID="RentalValueTextBox" runat="server"

Text='<%# Bind("RentalValue") %>' />

</td>

<td>

<asp:TextBox ID="LandLocationTextBox" runat="server"

Text='<%# Bind("LandLocation") %>' />

</td>

</tr>

</edititemtemplate>

<emptydatatemplate>

<table runat="server"

style="">

<tr>

<td>

No data was returned.</td>

</tr>

</table>

</emptydatatemplate>

<insertitemtemplate>

<tr runat="server" style="">

<td>

<asp:Button ID="InsertButton" runat="server" CommandName="Insert"

Text="Insert" />

<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"

Text="Clear" />

</td>

<td>

<asp:TextBox ID="TaxFileIDTextBox" runat="server"

Text='<%# Bind("TaxFileID") %>' />

</td>

<td>

<asp:TextBox ID="FiscalYearIDTextBox" runat="server"

Text='<%# Bind("FiscalYearID") %>' />

</td>

<td>

<asp:TextBox ID="LandDimensionsTextBox" runat="server"

Text='<%# Bind("LandDimensions") %>' />

</td>

<td>

<asp:TextBox ID="RentalValueTextBox" runat="server"

Text='<%# Bind("RentalValue") %>' />

</td>

<td>

<asp:TextBox ID="LandLocationTextBox" runat="server"

Text='<%# Bind("LandLocation") %>' />

</td>

</tr>

</insertitemtemplate>

<itemtemplate>

<tr runat="server" style="">

<td>

<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"

Text="Delete" />

<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />

</td>

<td>

<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />

</td>

<td>

<asp:Label ID="TaxFileIDLabel" runat="server"

Text='<%# Eval("TaxFileID") %>' />

</td>

<td>

<asp:Label ID="FiscalYearIDLabel" runat="server"

Text='<%# Eval("FiscalYearID") %>' />

</td>

<td>

<asp:Label ID="LandDimensionsLabel" runat="server"

Text='<%# Eval("LandDimensions") %>' />

</td>

<td>

<asp:Label ID="RentalValueLabel" runat="server"

Text='<%# Eval("RentalValue") %>' />

</td>

<td>

<asp:Label ID="LandLocationLabel" runat="server"

Text='<%# Eval("LandLocation") %>' />

</td>

</tr>

</itemtemplate>

<layouttemplate>

<table runat="server">

<tr runat="server">

<td runat="server">

<table runat="server" border="0" style="">

<thead runat="server">

<tr runat="server" style="">

<th runat="server">

</th>

<th runat="server">

ID</th>

<th runat="server">

TaxFileID</th>

<th runat="server">

FiscalYearID</th>

<th runat="server">

LandDimensions</th>

<th runat="server">

RentalValue</th>

<th runat="server">

LandLocation</th>

</tr>

</thead>

<tbody id="itemContainer" runat="server">

</tbody>

</table>

</td>

</tr>

<tr runat="server">

<td runat="server"

 

style="">

<asp:datapager ID="DataPager1" runat="server">

<fields>

<asp:nextpreviouspagerfield ButtonType="Button" FirstPageText="First"

LastPageText="Last" NextPageText="Next" PreviousPageText="Previous"

ShowFirstPageButton="True" ShowLastPageButton="True" />

</fields>

</asp:datapager>

</td>

</tr>

</table>

</layouttemplate>

<selecteditemtemplate>

<tr runat="server" style="">

<td>

<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"

Text="Delete" />

<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />

</td>

<td>

<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />

</td>

<td>

<asp:Label ID="TaxFileIDLabel" runat="server"

Text='<%# Eval("TaxFileID") %>' />

</td>

<td>

<asp:Label ID="FiscalYearIDLabel" runat="server"

Text='<%# Eval("FiscalYearID") %>' />

</td>

<td>

<asp:Label ID="LandDimensionsLabel" runat="server"

Text='<%# Eval("LandDimensions") %>' />

</td>

<td>

<asp:Label ID="RentalValueLabel" runat="server"

Text='<%# Eval("RentalValue") %>' />

</td>

<td>

<asp:Label ID="LandLocationLabel" runat="server"

Text='<%# Eval("LandLocation") %>' />

</td>

</tr>

</selecteditemtemplate>

</asp:listview>

"chetan.sarode"
NewsGroup User
Re: FindControl in Listview9/28/2007 3:38:41 AM

0

TextBox textBox = (TextBox)this.ListView1.FindControl("TaxFileIDTextBox");

Profile.TaxfileID = textBox.Text;


Chetan Sarode
Software Professional,
Extentia Information Technology,
Pune, India.
"SunfireGFX" <>
NewsGroup User
Re: FindControl in Listview9/28/2007 4:16:56 AM

0

still the same problem... Object reference not set to an instance of an object.

"dwhite" <>
NewsGroup User
Re: FindControl in Listview9/28/2007 12:12:30 PM

0

You need to do your FindControl in an item event (e.g. ItemCreated).  If you think about it; you have lots of the controls on the page with the same ID.

See http://www.singingeels.com/Articles/The_ListView_Dominates_The_Repeater.aspx for an example

For example:

private void MyListView_ItemCreated(object sender, ListViewItemEventArgs e)
{
   if (e.Item.ItemType == ListViewItemType.DataItem)
   {
       ListViewDataItem currentItem = (ListViewDataItem)e.Item;
       LinkButton SiteLink = (LinkButton)currentItem.FindControl("SiteLink");
   }
}
-Damien
** Remember to mark posts as the answer to help future users. **
Visoft, Inc - Web Site | Blogs
"SunfireGFX" <>
NewsGroup User
Re: FindControl in Listview9/28/2007 8:28:05 PM

0

i am very convinced with your theory, but when i tried to do it , i had the same problem, i tried to alter it in many ways but yet nothing seems to work.. any furthet idieas.!

"Jin-Yu Yin - M
NewsGroup User
Re: FindControl in Listview10/2/2007 9:08:53 AM

0

Hi,

The code your post up is too much.Would you please create a simple repro?

Thanks,


Sincerely,
Jin-Yu Yin
Microsoft Online Community Support
"chetan.sarode"
NewsGroup User
Re: FindControl in Listview10/3/2007 3:49:44 AM

0

Try to debug your application and check StackTrace for more details


Chetan Sarode
Software Professional,
Extentia Information Technology,
Pune, India.
"patcoston4" <>
NewsGroup User
Re: FindControl in Listview1/3/2008 6:05:36 PM

0

I have the same problem.  I am unable to find a control inside the ListView template InsertItemTemplate.  Below is small test case.  When I click the button MyButton, I want to make the panel HiddenPanel visible. 

<asp:ListView ID="MyListView" runat="server"

InsertItemPosition="LastItem"

DataSourceID="MySQL" DataKeyNames="id">

<LayoutTemplate>

<p />ABC

<asp:PlaceHolder runat="server" ID="itemPlaceHolder">

</asp:PlaceHolder>

<p />XYZ

</LayoutTemplate>

<ItemTemplate>x</ItemTemplate>

<InsertItemTemplate>

<p />INSERT

<asp:Button ID="MyButton" runat="server"

Text="Button" OnClick="MyButton_Click" />

<asp:Panel ID="HiddenPanel" runat="server" Visible="false">

Hello World!

</asp:Panel>

</InsertItemTemplate>

</asp:ListView>

<asp:SqlDataSource ID="MySQL" runat="server"

ConnectionString="<%$ ConnectionStrings:ConnStr %>"

SelectCommand="SELECT * FROM [MySQLTable]">

</asp:SqlDataSource>

I have tried various ways to parse the asp.net control tree DOM but so far I cannot find the panel object to change Visible=true.  Here are two methods I have tried.

protected void MyButton_Click(object sender, EventArgs e)

{

Panel p1 = MyListView.FindControl("HiddenPanel") as Panel;

if (p1 != null)

p1.Visible = true;for (int i = 0; i <= MyListView.Items.Count - 1; i++)

{

Panel p2 = MyListView.Items[i].FindControl("HiddenPanel") as Panel;

if (p2 != null)p2.Visible = true;

}

}

How can I find controls with the InsertItemTemplate when a button is clicked?
"patcoston4" <>
NewsGroup User
Re: FindControl in Listview1/7/2008 4:45:37 PM

0

I found a solution 

MyListView.HiddenTemplate.FindControl("HiddenPanel").Visible = true

9 Items, 1 Pages |< << Go >> >|



Free Download:






   
  Privacy | Contact Us
All Times Are GMT