473,569 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ItemCreated FindControl problem c#

All I need to do is set the border property of an image control to border=0.
I want to do this at runtime for the first image on the page in a datalist.
In the ItemCreated event I'm trying to use FindControl to set a reference to
the img control so I can change the attribute. But when I run the code below
I get the error: "Object reference not set to an instance of an object." I
assume its not finding the control and returning null? Anyway, you can see
what I'm trying to do, can anyone tell me how to get it to work? (code below)

******* code *******
public void main_ItemCreate d(Object sender, DataListItemEve ntArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em)
{
HtmlImage imgPatron = new HtmlImage();
imgPatron = (HtmlImage)e.It em.FindControl( Request.Form["patron"]);
if(imgPatron!=n ull)
{
image_count();
if(i_count == 1)
{
imgPatron.Borde r = 0;
}
}

}

************

Thanks for any help!
Nov 19 '05 #1
2 3174
Wrong event. I recommend using PreRender event since the page is fully built
at that stage. You can use ItemDataBound if you wish, but PreRender is
easier.

Eliyahu

"tparks69" <tp******@discu ssions.microsof t.com> wrote in message
news:B6******** *************** ***********@mic rosoft.com...
All I need to do is set the border property of an image control to border=0. I want to do this at runtime for the first image on the page in a datalist. In the ItemCreated event I'm trying to use FindControl to set a reference to the img control so I can change the attribute. But when I run the code below I get the error: "Object reference not set to an instance of an object." I assume its not finding the control and returning null? Anyway, you can see what I'm trying to do, can anyone tell me how to get it to work? (code below)
******* code *******
public void main_ItemCreate d(Object sender, DataListItemEve ntArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em)
{
HtmlImage imgPatron = new HtmlImage();
imgPatron = (HtmlImage)e.It em.FindControl( Request.Form["patron"]);
if(imgPatron!=n ull)
{
image_count();
if(i_count == 1)
{
imgPatron.Borde r = 0;
}
}

}

************

Thanks for any help!

Nov 19 '05 #2
What is exactly the "Request.Fo rm["patron"]"?

I think you should write:
.....FindContro l(ID/name of the server side control);
Hope this help

"tparks69" wrote:
All I need to do is set the border property of an image control to border=0.
I want to do this at runtime for the first image on the page in a datalist.
In the ItemCreated event I'm trying to use FindControl to set a reference to
the img control so I can change the attribute. But when I run the code below
I get the error: "Object reference not set to an instance of an object." I
assume its not finding the control and returning null? Anyway, you can see
what I'm trying to do, can anyone tell me how to get it to work? (code below)

******* code *******
public void main_ItemCreate d(Object sender, DataListItemEve ntArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em)
{
HtmlImage imgPatron = new HtmlImage();
imgPatron = (HtmlImage)e.It em.FindControl( Request.Form["patron"]);
if(imgPatron!=n ull)
{
image_count();
if(i_count == 1)
{
imgPatron.Borde r = 0;
}
}

}

************

Thanks for any help!

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
627
by: Kevin Hector | last post by:
Hi. Can anyone explain why, when setting the Text of a Label control in the ItemCreated event of a Repeater (example below), the Text value is NOT persisted to ViewState? I know this can be fixed by using the ItemDataBound event, but I don't understand why. here's a page snippet: <asp:Repeater runat="server" id="myRepeater"...
2
1170
by: Lars Netzel | last post by:
Hey! I have a ButtonColumn (PushButton) which I need to address in the DataGrid's ItemCreated to be able to set the Text on the ButtonColumn (yes I need to change this in runtime). regards /Lars Netzel
4
4366
by: Souri Challa | last post by:
Hello All, When a datagrid in a web form is getting re populated from view state on post back, it is firing the datagrid Item Created event but the DataGridItem(e.Item.DataItem is null) in the event arguments has no values. Is there any way to access and manipulate the row contents in this case ? Thanks in advance for any insigts in to...
9
2323
by: Manuel | last post by:
I have a Datagrid with 9 elements. The problem is that when I sort the grid by a column, it present more columns than there are. This is my code for the ItemCreated event: Private pNo As Integer = 0 Private Sub grd_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles grd.ItemCreated
1
1506
by: tshad | last post by:
I am trying understand when DataLists ItemCreated is called. I put function that attaches a popup to my delete button: Sub DataList_ItemCreated(Sender As Object, e As DataListItemEventArgs) trace.warn("Inside DataList_ItemCreated Sender = " & sender.GetType().tostring()) trace.warn("Itemtype = " & e.Item.ItemType & " " &...
0
813
by: tparks69 | last post by:
All I want to do is change the border of the first img control in my html to 0. The other images I want to have border=1. I have an event on my datalist that calls the following code: ************** public void main_ItemCreated(Object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item) { HtmlImage imgPatron =...
4
15291
by: Dennis E. Jones, Jr. | last post by:
I'm creating a dynamic control for each row in a REPEATER based on database values. ItemDataBound creates the control for the initial load (not postback), but I cannot get the control recreated when command to save data (postback) occurs. How do I get the values for this dynamic control on postback and place the control back into its...
0
1659
by: fig000 | last post by:
Hi, I have a datalist with bound data from a database. If I wanted to access one of the fields I would normally use the itemdatabound event to access that field on each row. However in this case I want to be able to click one button (not a button on each row of the datalist) and have the code run through each row of the datalist and...
0
2379
by: K B | last post by:
Hi, I have a DetailsView and on the ItemCreated event I can hide a control based on meeting criteria, but I can not figure out how to hide the row. Example, If ddlType.selectedvalue = 1 Then Dim t As TextBox = CType(dvInitiateJob.FindControl("ActualEndDate"), Control) 'HIDE THE ROW WITH 'ActualEndDate' textbox control
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.