473,408 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

ItemDataBoundEventHandler

I have an event ItemDataBoundEventHandler which handles
DataGrid1.ItemDataBound. This event applies special formatting to a webform
datagrid at bind-time. I've noticed, however, that when the page containing
this datagrid is posted-back all formatting is lost. Basically when I open
the page the datagrid looks good, but as soon as a postback occurs the
formatting is wiped-out. How could I prevent postback from doing this?
Thanks!
Nov 18 '05 #1
7 1448
I just tried something similar but didn't have any problems. Can you post
the code for the ItemDataBoundEventHandler

Cheers, Pete

"MrMike" <Mr****@discussions.microsoft.com> wrote in message
news:A0**********************************@microsof t.com...
I have an event ItemDataBoundEventHandler which handles
DataGrid1.ItemDataBound. This event applies special formatting to a webform datagrid at bind-time. I've noticed, however, that when the page containing this datagrid is posted-back all formatting is lost. Basically when I open the page the datagrid looks good, but as soon as a postback occurs the
formatting is wiped-out. How could I prevent postback from doing this?
Thanks!

Nov 18 '05 #2
Sure. Here is the ItemDataBoundEventHandler and the HTML for the affected
column (Column1). Let me explain...
Column(1) of my datagrid is a hyperlink column. Basically if a value exists
in "ImageFilePath" then I want to display the hyperlink in that datagrid row.
If a value does not exist in "ImageFilePath" then I don't want anything to
dispaly. This works correctly, but as soon as the page is posted-back all
columns have the hyperlink. Thanks.

Sub ItemDataBoundEventHandler(ByVal sender As Object, ByVal e As
DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then

Dim imagefilepath As String
imagefilepath =
Convert.ToString(DataBinder.Eval(e.Item.DataItem, "ImageFilePath"))

If imagefilepath = "" Then
e.Item.Cells(1).Text = ""
End If

End If
End Sub

<HTML>
<asp:TemplateColumn>
<HeaderStyle Wrap="False"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:HyperLink runat="server" Text="picture" NavigateURL='<%#
DataBinder.Eval(Container, "DataItem.ImageFilePath") %> ' Target="_blank"
ID="HL99" Name="HyperLink1">
</asp:HyperLink>
</ItemTemplate>
<FooterStyle Wrap="False"></FooterStyle>
</asp:TemplateColumn>
</HTML>

"pete" wrote:
I just tried something similar but didn't have any problems. Can you post
the code for the ItemDataBoundEventHandler

Cheers, Pete

"MrMike" <Mr****@discussions.microsoft.com> wrote in message
news:A0**********************************@microsof t.com...
I have an event ItemDataBoundEventHandler which handles
DataGrid1.ItemDataBound. This event applies special formatting to a

webform
datagrid at bind-time. I've noticed, however, that when the page

containing
this datagrid is posted-back all formatting is lost. Basically when I

open
the page the datagrid looks good, but as soon as a postback occurs the
formatting is wiped-out. How could I prevent postback from doing this?
Thanks!


Nov 18 '05 #3
Sure. Here is the ItemDataBoundEventHandler and the HTML for the affected
column (Column1). Let me explain...
Column(1) of my datagrid is a hyperlink column. Basically if a value exists
in "ImageFilePath" then I want to display the hyperlink in that datagrid row.
If a value does not exist in "ImageFilePath" then I don't want anything to
dispaly. This works correctly, but as soon as the page is posted-back all
columns have the hyperlink. Thanks.

Sub ItemDataBoundEventHandler(ByVal sender As Object, ByVal e As
DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then

Dim imagefilepath As String
imagefilepath =
Convert.ToString(DataBinder.Eval(e.Item.DataItem, "ImageFilePath"))

If imagefilepath = "" Then
e.Item.Cells(1).Text = ""
End If

End If
End Sub

<HTML>
<asp:TemplateColumn>
<HeaderStyle Wrap="False"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:HyperLink runat="server" Text="picture" NavigateURL='<%#
DataBinder.Eval(Container, "DataItem.ImageFilePath") %> ' Target="_blank"
ID="HL99" Name="HyperLink1">
</asp:HyperLink>
</ItemTemplate>
<FooterStyle Wrap="False"></FooterStyle>
</asp:TemplateColumn>
</HTML>

"pete" wrote:
I just tried something similar but didn't have any problems. Can you post
the code for the ItemDataBoundEventHandler

Cheers, Pete

"MrMike" <Mr****@discussions.microsoft.com> wrote in message
news:A0**********************************@microsof t.com...
I have an event ItemDataBoundEventHandler which handles
DataGrid1.ItemDataBound. This event applies special formatting to a

webform
datagrid at bind-time. I've noticed, however, that when the page

containing
this datagrid is posted-back all formatting is lost. Basically when I

open
the page the datagrid looks good, but as soon as a postback occurs the
formatting is wiped-out. How could I prevent postback from doing this?
Thanks!


Nov 18 '05 #4
Hi Mike,

I've just ran some tests here and can recreate your problem. However, in
order to do so I have to:

1) Bind the datagrid only on the first page load i.e. if
(!Page.IsPostBack)
2) Enable viewstate for the datagrid

Is this what your doing?

Pete

"MrMike" <Mr****@discussions.microsoft.com> wrote in message
news:0A**********************************@microsof t.com...
Sure. Here is the ItemDataBoundEventHandler and the HTML for the affected
column (Column1). Let me explain...
Column(1) of my datagrid is a hyperlink column. Basically if a value exists in "ImageFilePath" then I want to display the hyperlink in that datagrid row. If a value does not exist in "ImageFilePath" then I don't want anything to dispaly. This works correctly, but as soon as the page is posted-back all
columns have the hyperlink. Thanks.

Sub ItemDataBoundEventHandler(ByVal sender As Object, ByVal e As
DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then

Dim imagefilepath As String
imagefilepath =
Convert.ToString(DataBinder.Eval(e.Item.DataItem, "ImageFilePath"))

If imagefilepath = "" Then
e.Item.Cells(1).Text = ""
End If

End If
End Sub

<HTML>
<asp:TemplateColumn>
<HeaderStyle Wrap="False"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:HyperLink runat="server" Text="picture" NavigateURL='<%#
DataBinder.Eval(Container, "DataItem.ImageFilePath") %> ' Target="_blank"
ID="HL99" Name="HyperLink1">
</asp:HyperLink>
</ItemTemplate>
<FooterStyle Wrap="False"></FooterStyle>
</asp:TemplateColumn>
</HTML>

"pete" wrote:
I just tried something similar but didn't have any problems. Can you post the code for the ItemDataBoundEventHandler

Cheers, Pete

"MrMike" <Mr****@discussions.microsoft.com> wrote in message
news:A0**********************************@microsof t.com...
I have an event ItemDataBoundEventHandler which handles
DataGrid1.ItemDataBound. This event applies special formatting to a

webform
datagrid at bind-time. I've noticed, however, that when the page

containing
this datagrid is posted-back all formatting is lost. Basically when I

open
the page the datagrid looks good, but as soon as a postback occurs the
formatting is wiped-out. How could I prevent postback from doing this? Thanks!


Nov 18 '05 #5
pete, Yes to both questions. Thanks for your ongoing assistance!

"pete" wrote:
Hi Mike,

I've just ran some tests here and can recreate your problem. However, in
order to do so I have to:

1) Bind the datagrid only on the first page load i.e. if
(!Page.IsPostBack)
2) Enable viewstate for the datagrid

Is this what your doing?

Pete

"MrMike" <Mr****@discussions.microsoft.com> wrote in message
news:0A**********************************@microsof t.com...
Sure. Here is the ItemDataBoundEventHandler and the HTML for the affected
column (Column1). Let me explain...
Column(1) of my datagrid is a hyperlink column. Basically if a value

exists
in "ImageFilePath" then I want to display the hyperlink in that datagrid

row.
If a value does not exist in "ImageFilePath" then I don't want anything

to
dispaly. This works correctly, but as soon as the page is posted-back all
columns have the hyperlink. Thanks.

Sub ItemDataBoundEventHandler(ByVal sender As Object, ByVal e As
DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then

Dim imagefilepath As String
imagefilepath =
Convert.ToString(DataBinder.Eval(e.Item.DataItem, "ImageFilePath"))

If imagefilepath = "" Then
e.Item.Cells(1).Text = ""
End If

End If
End Sub

<HTML>
<asp:TemplateColumn>
<HeaderStyle Wrap="False"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:HyperLink runat="server" Text="picture" NavigateURL='<%#
DataBinder.Eval(Container, "DataItem.ImageFilePath") %> ' Target="_blank"
ID="HL99" Name="HyperLink1">
</asp:HyperLink>
</ItemTemplate>
<FooterStyle Wrap="False"></FooterStyle>
</asp:TemplateColumn>
</HTML>

"pete" wrote:
I just tried something similar but didn't have any problems. Can you post the code for the ItemDataBoundEventHandler

Cheers, Pete

"MrMike" <Mr****@discussions.microsoft.com> wrote in message
news:A0**********************************@microsof t.com...
> I have an event ItemDataBoundEventHandler which handles
> DataGrid1.ItemDataBound. This event applies special formatting to a
webform
> datagrid at bind-time. I've noticed, however, that when the page
containing
> this datagrid is posted-back all formatting is lost. Basically when I
open
> the page the datagrid looks good, but as soon as a postback occurs the
> formatting is wiped-out. How could I prevent postback from doing this? > Thanks!


Nov 18 '05 #6
Glad to help.

The ItemDataBound event fires when you call the DataGridx.DataBind() method
(or the Page.DataBind() method which will make the call for you). Your code
only calls DataBind on first load and not on subsequent postbacks. To get
round this problem you will need to bind the DataGrid on each Page Load.

If you decide to do this, set the EnableViewState to false as the Datagrid
control will no longer need to retrieve its content from viewstate. If you
look at the html which is output to the browser, you should see that the
hidden _Viewstate field is considerably shorter.

Best of luck, Pete

"MrMike" <Mr****@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
pete, Yes to both questions. Thanks for your ongoing assistance!

"pete" wrote:
Hi Mike,

I've just ran some tests here and can recreate your problem. However, in
order to do so I have to:

1) Bind the datagrid only on the first page load i.e. if
(!Page.IsPostBack)
2) Enable viewstate for the datagrid

Is this what your doing?

Pete

"MrMike" <Mr****@discussions.microsoft.com> wrote in message
news:0A**********************************@microsof t.com...
Sure. Here is the ItemDataBoundEventHandler and the HTML for the affected column (Column1). Let me explain...
Column(1) of my datagrid is a hyperlink column. Basically if a value

exists
in "ImageFilePath" then I want to display the hyperlink in that datagrid
row.
If a value does not exist in "ImageFilePath" then I don't want
anything to
dispaly. This works correctly, but as soon as the page is posted-back

all columns have the hyperlink. Thanks.

Sub ItemDataBoundEventHandler(ByVal sender As Object, ByVal e As
DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then

Dim imagefilepath As String
imagefilepath =
Convert.ToString(DataBinder.Eval(e.Item.DataItem, "ImageFilePath"))

If imagefilepath = "" Then
e.Item.Cells(1).Text = ""
End If

End If
End Sub

<HTML>
<asp:TemplateColumn>
<HeaderStyle Wrap="False"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:HyperLink runat="server" Text="picture" NavigateURL='<%#
DataBinder.Eval(Container, "DataItem.ImageFilePath") %> ' Target="_blank" ID="HL99" Name="HyperLink1">
</asp:HyperLink>
</ItemTemplate>
<FooterStyle Wrap="False"></FooterStyle>
</asp:TemplateColumn>
</HTML>

"pete" wrote:

> I just tried something similar but didn't have any problems. Can you

post
> the code for the ItemDataBoundEventHandler
>
> Cheers, Pete
>
> "MrMike" <Mr****@discussions.microsoft.com> wrote in message
> news:A0**********************************@microsof t.com...
> > I have an event ItemDataBoundEventHandler which handles
> > DataGrid1.ItemDataBound. This event applies special formatting to a > webform
> > datagrid at bind-time. I've noticed, however, that when the page
> containing
> > this datagrid is posted-back all formatting is lost. Basically when I > open
> > the page the datagrid looks good, but as soon as a postback occurs the > > formatting is wiped-out. How could I prevent postback from doing

this?
> > Thanks!
>
>
>


Nov 18 '05 #7
Pete, What I've done is added a call to the sub that performs the bind at the
end of this sub. That solved the problem! Thanks for your help.

"pete" wrote:
Glad to help.

The ItemDataBound event fires when you call the DataGridx.DataBind() method
(or the Page.DataBind() method which will make the call for you). Your code
only calls DataBind on first load and not on subsequent postbacks. To get
round this problem you will need to bind the DataGrid on each Page Load.

If you decide to do this, set the EnableViewState to false as the Datagrid
control will no longer need to retrieve its content from viewstate. If you
look at the html which is output to the browser, you should see that the
hidden _Viewstate field is considerably shorter.

Best of luck, Pete

"MrMike" <Mr****@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
pete, Yes to both questions. Thanks for your ongoing assistance!

"pete" wrote:
Hi Mike,

I've just ran some tests here and can recreate your problem. However, in
order to do so I have to:

1) Bind the datagrid only on the first page load i.e. if
(!Page.IsPostBack)
2) Enable viewstate for the datagrid

Is this what your doing?

Pete

"MrMike" <Mr****@discussions.microsoft.com> wrote in message
news:0A**********************************@microsof t.com...
> Sure. Here is the ItemDataBoundEventHandler and the HTML for the affected > column (Column1). Let me explain...
> Column(1) of my datagrid is a hyperlink column. Basically if a value
exists
> in "ImageFilePath" then I want to display the hyperlink in that datagrid row.
> If a value does not exist in "ImageFilePath" then I don't want anything to
> dispaly. This works correctly, but as soon as the page is posted-back all > columns have the hyperlink. Thanks.
>
> Sub ItemDataBoundEventHandler(ByVal sender As Object, ByVal e As
> DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
> If e.Item.ItemType = ListItemType.Item Or _
> e.Item.ItemType = ListItemType.AlternatingItem Then
>
> Dim imagefilepath As String
> imagefilepath =
> Convert.ToString(DataBinder.Eval(e.Item.DataItem, "ImageFilePath"))
>
> If imagefilepath = "" Then
> e.Item.Cells(1).Text = ""
> End If
>
> End If
> End Sub
>
> <HTML>
> <asp:TemplateColumn>
> <HeaderStyle Wrap="False"></HeaderStyle>
> <ItemStyle Wrap="False"></ItemStyle>
> <ItemTemplate>
> <asp:HyperLink runat="server" Text="picture" NavigateURL='<%#
> DataBinder.Eval(Container, "DataItem.ImageFilePath") %> ' Target="_blank" > ID="HL99" Name="HyperLink1">
> </asp:HyperLink>
> </ItemTemplate>
> <FooterStyle Wrap="False"></FooterStyle>
> </asp:TemplateColumn>
> </HTML>
>
> "pete" wrote:
>
> > I just tried something similar but didn't have any problems. Can you
post
> > the code for the ItemDataBoundEventHandler
> >
> > Cheers, Pete
> >
> > "MrMike" <Mr****@discussions.microsoft.com> wrote in message
> > news:A0**********************************@microsof t.com...
> > > I have an event ItemDataBoundEventHandler which handles
> > > DataGrid1.ItemDataBound. This event applies special formatting to a > > webform
> > > datagrid at bind-time. I've noticed, however, that when the page
> > containing
> > > this datagrid is posted-back all formatting is lost. Basically when I > > open
> > > the page the datagrid looks good, but as soon as a postback occurs the > > > formatting is wiped-out. How could I prevent postback from doing
this?
> > > Thanks!
> >
> >
> >


Nov 18 '05 #8

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

Similar topics

3
by: shamila | last post by:
we are trying to pass a value to format a value in the datacolumn. But when we pass the datacolumn , it does not give me the value in the column, instead gives me the column name. the following...
0
by: shamila | last post by:
</asp:label><asp:datagrid id="DataGrid3" runat="server" cssclass="DataGrid" showfooter="True" onupdatecommand="DataGrid3_Update"ondeletecommand="DataGrid3_Delete" oneditcommand="DataGrid3_Edit"...
2
by: andla | last post by:
Hi, How does events fire in a datagrid. I know about the problem if turning the viewstate off the events wil not fire properly even if I rebind the control in every postback. S then I started...
2
by: Wayne Wengert | last post by:
I have an ASP.NET page in which I include a datalist that is bound to a datareader. I am trying to use the OnItemDataBound event to change the contents of the NavigateURL property of a hyperlink. I...
1
by: euan | last post by:
HI Guys, I have bee using conditional formatting in the datagrid recently and I am moving over to framework 2.0 and noticed the datagrid has been replaced by the gridview. So, I would like to do...
0
by: simon | last post by:
hello, I was hoping someone could help me with an issue (using vb & .net 2.0) I have a datagrid and the first column shown i have an asp:textbox that i basically want to "group by" an ID and only...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.