473,378 Members | 1,355 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,378 software developers and data experts.

GridView RowDataBound not called after postback

I am trying to modify the layout of a row based on the value in some data (I
am creating a subtotal line). This works fine when the page is first loaded,
but when it's reloaded, the wrong column is restored.

<asp:GridView ID="grdvOrder" runat="server" AutoGenerateColumns="False"
OnRowCommand="grdvOrder_RowCommand" OnRowDataBound="grdvOrder_RowDataBound"
OnRowCreated="grdvOrder_RowCreated">
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server"
CausesValidation="false" CommandName="DeleteLine"
ImageUrl="~/Images/btn_delete.gif" Text="" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox ID="txtQty" runat="server" Columns="4"
Text='<%# Bind("QtyOrdered") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFields="Sku"
DataNavigateUrlFormatString="product/{0}"
DataTextField="ProductName" HeaderText="Product" />
<asp:BoundField DataField="ProductId" HeaderText="Id" />
<asp:BoundField DataField="Price" HeaderText="Price"
DataFormatString="{0:c}" HtmlEncode="False" />
<asp:BoundField DataField="ExtPrice" HeaderText="Ext. Price"
DataFormatString="{0:c}" HtmlEncode="False" />
</Columns>
</asp:GridView>
protected void grdvOrder_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Check for sub-total line
DataRowView rowView = (DataRowView)e.Row.DataItem;
if (Convert.ToInt32(rowView["OrderLineId"]) == 0)
{
// Remove columns 0, 1, 3, 4
e.Row.Cells.RemoveAt(0);
e.Row.Cells.RemoveAt(0);
e.Row.Cells.RemoveAt(1);
e.Row.Cells.RemoveAt(1);
// Make column 2 span columns 1-4
e.Row.Cells[0].ColumnSpan = 5;
// Remove the hyperlink from the subtotal line
HyperLink lnk = (HyperLink) e.Row.Cells[0].Controls[0];
lnk.NavigateUrl = null;
}
}
}

On postback, RowDataBound is not called and the columns are all wrong.

I tried the RowCreated event, which did get called on postbacks, but then
the HyperLink control was not defined so setting the NavigateUrl to null had
no effect, and on postback got a null for (DataRowView)e.Row.DataItem,
causing an exception.

Any recommendations on how I can adjust the contents based on the data in
the row?

Thanks in advance,

Dan
Feb 17 '06 #1
0 5211

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

Similar topics

1
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an...
3
by: K B | last post by:
Hi again, I've narrowed down my problem and am hoping to get some help to get the final answer. Gridview with dynamic child controls loads gv1.Databind calls RowDataBound event fine On the...
6
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the...
3
by: ryan.mclean | last post by:
Hello everyone, I'm in a bind, and I hope somebody can point me in the right direction. I have a gridview that is bound when it is not a postback. When the grid is bound, I remove the contents...
6
by: AG | last post by:
I have a gridview with a template column containing an imagebutton to delete the row. Under some condition I don't want the row to be deleted, so would like to remove the button. In the...
1
by: =?Utf-8?B?V2VzbGV5IERhdmlzLCBHZW5lcmFsIER5bmFtaWNz | last post by:
I'm moving from years with the datagrid to a new project, .net 2.0, using GridView controls. Per past practice, it is often a lot easier to inject controls (or special formatting) in RowDataBound...
0
by: F | last post by:
Hi, The funniest part of the problem described here is that I am not new to ASP.NET, but honestly here I have no idea about what's going on. I have a GridView with a data source that just...
17
by: ata | last post by:
Hi folks, Consider a gridview that's being bound to a ObjectDataSource that uses an adapter to handle data access logic. 1. How am I supposed to have a RowIndex column *without* modifying the...
4
by: jack | last post by:
Hi, Consider the following handler: protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e) { GridViewRow row = e.Row; if (row.RowType != DataControlRowType.DataRow)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.