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

ItemDataBound / RowDataBound Difference

I'm up against something else I used to easily do in a DataGrid that is
different in a GridView....

I used to access cells in non-visible columns in the ItemDataBound event.
The data was there - the column just wasen't visible.
In the Gridview, if a column is not visible, the data is not there in the
cell in the RowdataBound event. This means we don't have the presentation
flexibility we used to have in the DataGrid, no?

Am I missing something? Is there some other way in which I can deal with
non visible data?

--
Regards,
Gary Blakely
Jan 18 '07 #1
4 24595
Gary,

This didn't change from datagrid to gridvew. In both 1.1 and 2.0 any web
control with the Visible property set to false doesn't get rendered to the
client and doesn't come back in postbacks. If you are interested in getting
hidden values in postbacks, leave Visible=true and use css rule
display:none.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"GaryDean" <Ga******@newsgroups.nospamwrote in message
news:O8**************@TK2MSFTNGP06.phx.gbl...
I'm up against something else I used to easily do in a DataGrid that is
different in a GridView....

I used to access cells in non-visible columns in the ItemDataBound event.
The data was there - the column just wasen't visible.
In the Gridview, if a column is not visible, the data is not there in the
cell in the RowdataBound event. This means we don't have the presentation
flexibility we used to have in the DataGrid, no?

Am I missing something? Is there some other way in which I can deal with
non visible data?

--
Regards,
Gary Blakely


Jan 18 '07 #2
Hello Gary,

I think the behavior for InVisible columns in DataGrid and GridView control
should be identical. You can access them in ItemCreated(RowCreated) and
ItemDataBound(RowDataBound) event. I'm not sure what's the problem in your
certain page, one common issue is that we try finding control without first
detect the RowType(ItemType) of each Item/Row. Anyway, here is a test page
which works on my local side, you can also refer to it for your testing

===========aspx===================
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName] FROM
[Categories]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="CategoryID"
DataSourceID="SqlDataSource1"
OnRowCreated="GridView1_RowCreated" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="CategoryID"
HeaderText="CategoryID" InsertVisible="False"
ReadOnly="True" SortExpression="CategoryID" />
<asp:BoundField DataField="CategoryName"
HeaderText="CategoryName" SortExpression="CategoryName" />
<asp:TemplateField HeaderText="HiddenColumn"
Visible="false">
<ItemTemplate>
<asp:TextBox ID="txt1" runat="server"
></asp:TextBox>
<asp:Button ID="btn1" runat="server" Text="Button1"
/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<br />
&nbsp;<asp:DataGrid ID="DataGrid1" runat="server"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
OnItemCreated="DataGrid1_ItemCreated"
OnItemDataBound="DataGrid1_ItemDataBound">
<Columns>
<asp:BoundColumn DataField="CategoryID"></asp:BoundColumn>
<asp:BoundColumn DataField="CategoryName"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="HiddenColumn"
Visible="false" >
<ItemTemplate>
<asp:TextBox ID="txt2" runat="server"></asp:TextBox>
<asp:Button ID="btn2" runat="server" Text="Button"
/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid></div>
</form>
==================================

==========codebehind=================
public partial class Part1_ASPSQLPAGE : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Control txt = e.Row.FindControl("txt1");
Response.Write("<br/>GridView1_RowCreated:" + txt);
}
}

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Control txt = e.Row.FindControl("txt1");
Response.Write("<br/>GridView1_RowDataBound:" + txt);
}
}

protected void DataGrid1_ItemCreated(object sender,
DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Control txt = e.Item.FindControl("txt2");
Response.Write("<br/>DataGrid1_ItemCreated:" + txt);
}
}
protected void DataGrid1_ItemDataBound(object sender,
DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Control txt = e.Item.FindControl("txt2");
Response.Write("<br/>DataGrid1_ItemDataBound: " + txt);
}
}
}
=================================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 18 '07 #3
Maybe my recollection of non-visible columns being there at ItemDataBound
time was a false memory. I don't have time to go check back on my old code
right now but I solved the issue in the GrivView by controlling visibility
at the Cell level in the RowDataBound event of the Gridview (probably the
way I used to do it).

thanks for your help.
Gary Blakely

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:3l**************@TK2MSFTNGHUB02.phx.gbl...
Hello Gary,

I think the behavior for InVisible columns in DataGrid and GridView
control
should be identical. You can access them in ItemCreated(RowCreated) and
ItemDataBound(RowDataBound) event. I'm not sure what's the problem in
your
certain page, one common issue is that we try finding control without
first
detect the RowType(ItemType) of each Item/Row. Anyway, here is a test page
which works on my local side, you can also refer to it for your testing

===========aspx===================
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName] FROM
[Categories]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="CategoryID"
DataSourceID="SqlDataSource1"
OnRowCreated="GridView1_RowCreated"
OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="CategoryID"
HeaderText="CategoryID" InsertVisible="False"
ReadOnly="True" SortExpression="CategoryID" />
<asp:BoundField DataField="CategoryName"
HeaderText="CategoryName" SortExpression="CategoryName" />
<asp:TemplateField HeaderText="HiddenColumn"
Visible="false">
<ItemTemplate>
<asp:TextBox ID="txt1" runat="server"
>></asp:TextBox>
<asp:Button ID="btn1" runat="server" Text="Button1"
/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<br />
&nbsp;<asp:DataGrid ID="DataGrid1" runat="server"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
OnItemCreated="DataGrid1_ItemCreated"
OnItemDataBound="DataGrid1_ItemDataBound">
<Columns>
<asp:BoundColumn DataField="CategoryID"></asp:BoundColumn>
<asp:BoundColumn
DataField="CategoryName"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="HiddenColumn"
Visible="false" >
<ItemTemplate>
<asp:TextBox ID="txt2"
runat="server"></asp:TextBox>
<asp:Button ID="btn2" runat="server" Text="Button"
/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid></div>
</form>
==================================

==========codebehind=================
public partial class Part1_ASPSQLPAGE : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Control txt = e.Row.FindControl("txt1");
Response.Write("<br/>GridView1_RowCreated:" + txt);
}
}

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Control txt = e.Row.FindControl("txt1");
Response.Write("<br/>GridView1_RowDataBound:" + txt);
}
}

protected void DataGrid1_ItemCreated(object sender,
DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Control txt = e.Item.FindControl("txt2");
Response.Write("<br/>DataGrid1_ItemCreated:" + txt);
}
}
protected void DataGrid1_ItemDataBound(object sender,
DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Control txt = e.Item.FindControl("txt2");
Response.Write("<br/>DataGrid1_ItemDataBound: " + txt);
}
}
}
=================================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 22 '07 #4
Thanks for your followup Gary,

If you meet any other problems or anything else we can help, please feel
free to post here.

Good luck!

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 23 '07 #5

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

Similar topics

3
by: Clouds | last post by:
Hi ! How do I add the dynamic event handler for a dropdownlist present in the itemtemplate of a datalist !! I am doing it in the itemdatabound event of the datalist but it doesnt work... I am...
3
by: MasterChief | last post by:
I am trying to add an attribute to a gridview row so when you click on it, it will pop up an alert saying the current datakey for that row. How is it possible to get a datakey when using the...
0
by: tfsmag | last post by:
I'm having a weird problem with the rowdatabound event for a gridview in my application... Here is the code. -------------------------------------- Protected Sub AnswersGrid_RowDataBound(ByVal...
1
by: Sukh | last post by:
I'm new to ASP.NET 2. In the prev. version i was able to do a lot of parsing and other changes in the Item_DataBound Method of DataGrid, and I wasn't able to find its equivalent with GridView. Am i...
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...
2
by: Tina | last post by:
In the ItemDataBound event of the DataGrid "Item" is a property so I can say e.item.... But in the GridView ItemDataBound event there is no "Item" What goes? How can I get anything done...
1
by: GaryDean | last post by:
It seems every time I try to use the GridView to do what I used to do with the DataGrid I run into differences that make me want to got back to the datagrid. for instance... the DataGrid...
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...
2
by: Tim | last post by:
I'm using a GridView with its DataSource property set to a DataTable. During the RowDataBound event, the first row of the DataTable is reported as a DataControlRowType.Header instead of...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.