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

2 datagrids on one page

I have 2 datagrids, both with databound columns that I have dynamically
added. I have an EditCommandColumn on both grids. EnableViewState is
enabled on both of the grids.

When I click the edit link on the grids I need to repopulate/rebind the
grids which I presume is correct.

When I click the update button I cannot find my databound columns that I
have edited. I have searched google and tried all the obvious examples, but
I am just not getting it. Is there perhaps a bug, or a limitation with
having 2 grids on one page. What exactly does EnableViewState do anyway if
it doesn't retain the data or already loaded in the grids? Here is my code
for populating one of the grids - the other is very similiar. If anyone has
any idea then please let me know as I am really stuck now...

Page Load....

dgPhotos.AutoGenerateColumns = False
If dgPhotos.Columns.Count = 5 Then

' Create ID column & add to DataGrid
Dim col1 As New BoundColumn
col1.HeaderText = "Description"
col1.DataField = "PhotoText"
dgPhotos.Columns.Add(col1)
col1 = Nothing

Dim col2 As New BoundColumn
col2.HeaderText = "Filename"
col2.DataField = "Filename"
col2.ReadOnly = True
dgPhotos.Columns.Add(col2)
col2 = Nothing

Dim col3 As New BoundColumn
col3.HeaderText = "Order"
col3.DataField = "OrderPos"
col3.ReadOnly = True
col3.Visible = False
dgPhotos.Columns.Add(col3)
col3 = Nothing
End If

dsPhotos.ReadXml(filePath)

dgPhotos.Visible = False
If dsPhotos.Tables.Count > 0 Then

dgPhotos.Visible = True

Dim lngID As Long
lngID = GetAlbumID(dsPhotos, strRoleID)

dvPhotos.Table = dsPhotos.Tables(1)
dvPhotos.RowFilter = "AlbumRoleID_Id = '" & lngID & "'"
dvPhotos.Sort = "OrderPos"

With dgPhotos
.DataSource = dvPhotos
.DataMember = "PhotoItem"
.DataBind()
End With
End If

Editing Code:

Private Sub dgPhotos_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgPhotos.EditCommand
dgPhotos.EditItemIndex = e.Item.ItemIndex

Dim strRoleID As String
PopulateGrid() 'Rebinds also

End Sub

Update Code so far :

Private Sub dgPhotos_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgPhotos.UpdateCommand

Dim txtDescription As New TextBox
txtDescription = CType(e.Item.Cells(1).FindControl("PhotoText"),
TextBox)
End Sub

aspx...
<asp:datagrid id="dgPhotos" runat="server" CssClass="aspTable"
ForeColor="Black" Font-Size="XX-Small"
AutoGenerateColumns="False" PageSize="15" Width="100%"
CellSpacing="2" AllowPaging="True" BorderColor="#999999"
BorderStyle="Solid" BorderWidth="3px" BackColor="#CCCCCC"
CellPadding="4">
<SelectedItemStyle Font-Size="XX-Small" Font-Bold="True"
ForeColor="White" BackColor="#000099"></SelectedItemStyle>
<EditItemStyle Font-Size="XX-Small"></EditItemStyle>
<AlternatingItemStyle Font-Size="XX-Small"></AlternatingItemStyle>
<ItemStyle Font-Size="XX-Small" BackColor="White"></ItemStyle>
<HeaderStyle Font-Size="XX-Small" Font-Bold="True" ForeColor="White"
BackColor="Black"></HeaderStyle>
<FooterStyle Font-Size="XX-Small" BackColor="#CCCCCC"></FooterStyle>
<Columns>
<asp:ButtonColumn Text="Up" ButtonType="PushButton"
CommandName="Up"></asp:ButtonColumn>
<asp:ButtonColumn Text="Down" ButtonType="PushButton"
CommandName="Down"></asp:ButtonColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit">
<HeaderStyle Font-Size="XX-Small"></HeaderStyle>
<ItemStyle Font-Size="XX-Small"></ItemStyle>
<FooterStyle Font-Size="XX-Small"></FooterStyle>
</asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete">
<HeaderStyle Font-Size="XX-Small"></HeaderStyle>
<ItemStyle Font-Size="XX-Small"></ItemStyle>
<FooterStyle Font-Size="XX-Small"></FooterStyle>
</asp:ButtonColumn>
<asp:TemplateColumn HeaderText="Photo">
<ItemTemplate>
<asp:Image runat=server
ImageUrl='<%#ReturnSmallURL(DataBinder.Eval(contai ner.dataitem, "filename"),
dgAlbums.Items(dgAlbums.SelectedIndex).Cells.Item( 7).Text)%>' ID="Image2"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Font-Size="XX-Small" HorizontalAlign="Left"
ForeColor="Black" BackColor="#CCCCCC"
Mode="NumericPages"></PagerStyle>
</asp:datagrid>
Nov 18 '05 #1
2 1197
the Page Load fires again BEFORE the UpdateCommand event ... be sure to only
'fill' the grid if the page is not posted back ...

use:

if not ispostback then
'do stuff
end if

"Philip Rayne" <pr****@noemail.com> wrote in message
news:vd******************@cyclops.nntpserver.com.. .
I have 2 datagrids, both with databound columns that I have dynamically
added. I have an EditCommandColumn on both grids. EnableViewState is
enabled on both of the grids.

When I click the edit link on the grids I need to repopulate/rebind the
grids which I presume is correct.

When I click the update button I cannot find my databound columns that I
have edited. I have searched google and tried all the obvious examples, but I am just not getting it. Is there perhaps a bug, or a limitation with
having 2 grids on one page. What exactly does EnableViewState do anyway if it doesn't retain the data or already loaded in the grids? Here is my code for populating one of the grids - the other is very similiar. If anyone has any idea then please let me know as I am really stuck now...

Page Load....

dgPhotos.AutoGenerateColumns = False
If dgPhotos.Columns.Count = 5 Then

' Create ID column & add to DataGrid
Dim col1 As New BoundColumn
col1.HeaderText = "Description"
col1.DataField = "PhotoText"
dgPhotos.Columns.Add(col1)
col1 = Nothing

Dim col2 As New BoundColumn
col2.HeaderText = "Filename"
col2.DataField = "Filename"
col2.ReadOnly = True
dgPhotos.Columns.Add(col2)
col2 = Nothing

Dim col3 As New BoundColumn
col3.HeaderText = "Order"
col3.DataField = "OrderPos"
col3.ReadOnly = True
col3.Visible = False
dgPhotos.Columns.Add(col3)
col3 = Nothing
End If

dsPhotos.ReadXml(filePath)

dgPhotos.Visible = False
If dsPhotos.Tables.Count > 0 Then

dgPhotos.Visible = True

Dim lngID As Long
lngID = GetAlbumID(dsPhotos, strRoleID)

dvPhotos.Table = dsPhotos.Tables(1)
dvPhotos.RowFilter = "AlbumRoleID_Id = '" & lngID & "'"
dvPhotos.Sort = "OrderPos"

With dgPhotos
.DataSource = dvPhotos
.DataMember = "PhotoItem"
.DataBind()
End With
End If

Editing Code:

Private Sub dgPhotos_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgPhotos.EditCommand
dgPhotos.EditItemIndex = e.Item.ItemIndex

Dim strRoleID As String
PopulateGrid() 'Rebinds also

End Sub

Update Code so far :

Private Sub dgPhotos_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgPhotos.UpdateCommand

Dim txtDescription As New TextBox
txtDescription = CType(e.Item.Cells(1).FindControl("PhotoText"),
TextBox)
End Sub

aspx...
<asp:datagrid id="dgPhotos" runat="server" CssClass="aspTable"
ForeColor="Black" Font-Size="XX-Small"
AutoGenerateColumns="False" PageSize="15" Width="100%"
CellSpacing="2" AllowPaging="True" BorderColor="#999999"
BorderStyle="Solid" BorderWidth="3px" BackColor="#CCCCCC"
CellPadding="4">
<SelectedItemStyle Font-Size="XX-Small" Font-Bold="True"
ForeColor="White" BackColor="#000099"></SelectedItemStyle>
<EditItemStyle Font-Size="XX-Small"></EditItemStyle>
<AlternatingItemStyle Font-Size="XX-Small"></AlternatingItemStyle>
<ItemStyle Font-Size="XX-Small" BackColor="White"></ItemStyle>
<HeaderStyle Font-Size="XX-Small" Font-Bold="True" ForeColor="White" BackColor="Black"></HeaderStyle>
<FooterStyle Font-Size="XX-Small" BackColor="#CCCCCC"></FooterStyle> <Columns>
<asp:ButtonColumn Text="Up" ButtonType="PushButton"
CommandName="Up"></asp:ButtonColumn>
<asp:ButtonColumn Text="Down" ButtonType="PushButton"
CommandName="Down"></asp:ButtonColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit">
<HeaderStyle Font-Size="XX-Small"></HeaderStyle>
<ItemStyle Font-Size="XX-Small"></ItemStyle>
<FooterStyle Font-Size="XX-Small"></FooterStyle>
</asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete">
<HeaderStyle Font-Size="XX-Small"></HeaderStyle>
<ItemStyle Font-Size="XX-Small"></ItemStyle>
<FooterStyle Font-Size="XX-Small"></FooterStyle>
</asp:ButtonColumn>
<asp:TemplateColumn HeaderText="Photo">
<ItemTemplate>
<asp:Image runat=server
ImageUrl='<%#ReturnSmallURL(DataBinder.Eval(contai ner.dataitem, "filename"), dgAlbums.Items(dgAlbums.SelectedIndex).Cells.Item( 7).Text)%>' ID="Image2"/> </ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Font-Size="XX-Small" HorizontalAlign="Left"
ForeColor="Black" BackColor="#CCCCCC"
Mode="NumericPages"></PagerStyle>
</asp:datagrid>

Nov 18 '05 #2
Hi, thanks for the info. I was already doing that.

I have now sorted the problem, but I don't really understand why it didn't
work in the first place.
Basically I have now removed the code that adds the columns in the code and
created them in the asp instead :

DataField="PhotoText" />
<asp:BoundColumn HeaderText="Filename" SortExpression="Filename"
DataField="Filename" ReadOnly="True" />
<asp:BoundColumn HeaderText="Order" SortExpression="OrderPos"
DataField="OrderPos" ReadOnly="True"

This now seems to work when I try and access the value of the edited cell.

"Thomas Dodds" <th*********@hotmail.com> wrote in message
news:e4**************@TK2MSFTNGP11.phx.gbl...
the Page Load fires again BEFORE the UpdateCommand event ... be sure to only 'fill' the grid if the page is not posted back ...

use:

if not ispostback then
'do stuff
end if

"Philip Rayne" <pr****@noemail.com> wrote in message
news:vd******************@cyclops.nntpserver.com.. .
I have 2 datagrids, both with databound columns that I have dynamically
added. I have an EditCommandColumn on both grids. EnableViewState is
enabled on both of the grids.

When I click the edit link on the grids I need to repopulate/rebind the
grids which I presume is correct.

When I click the update button I cannot find my databound columns that I
have edited. I have searched google and tried all the obvious examples,

but
I am just not getting it. Is there perhaps a bug, or a limitation with
having 2 grids on one page. What exactly does EnableViewState do anyway

if
it doesn't retain the data or already loaded in the grids? Here is my

code
for populating one of the grids - the other is very similiar. If anyone

has
any idea then please let me know as I am really stuck now...

Page Load....

dgPhotos.AutoGenerateColumns = False
If dgPhotos.Columns.Count = 5 Then

' Create ID column & add to DataGrid
Dim col1 As New BoundColumn
col1.HeaderText = "Description"
col1.DataField = "PhotoText"
dgPhotos.Columns.Add(col1)
col1 = Nothing

Dim col2 As New BoundColumn
col2.HeaderText = "Filename"
col2.DataField = "Filename"
col2.ReadOnly = True
dgPhotos.Columns.Add(col2)
col2 = Nothing

Dim col3 As New BoundColumn
col3.HeaderText = "Order"
col3.DataField = "OrderPos"
col3.ReadOnly = True
col3.Visible = False
dgPhotos.Columns.Add(col3)
col3 = Nothing
End If

dsPhotos.ReadXml(filePath)

dgPhotos.Visible = False
If dsPhotos.Tables.Count > 0 Then

dgPhotos.Visible = True

Dim lngID As Long
lngID = GetAlbumID(dsPhotos, strRoleID)

dvPhotos.Table = dsPhotos.Tables(1)
dvPhotos.RowFilter = "AlbumRoleID_Id = '" & lngID & "'"
dvPhotos.Sort = "OrderPos"

With dgPhotos
.DataSource = dvPhotos
.DataMember = "PhotoItem"
.DataBind()
End With
End If

Editing Code:

Private Sub dgPhotos_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgPhotos.EditCommand
dgPhotos.EditItemIndex = e.Item.ItemIndex

Dim strRoleID As String
PopulateGrid() 'Rebinds also

End Sub

Update Code so far :

Private Sub dgPhotos_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgPhotos.UpdateCommand

Dim txtDescription As New TextBox
txtDescription = CType(e.Item.Cells(1).FindControl("PhotoText"),
TextBox)
End Sub

aspx...
<asp:datagrid id="dgPhotos" runat="server" CssClass="aspTable"
ForeColor="Black" Font-Size="XX-Small"
AutoGenerateColumns="False" PageSize="15" Width="100%"
CellSpacing="2" AllowPaging="True" BorderColor="#999999"
BorderStyle="Solid" BorderWidth="3px" BackColor="#CCCCCC"
CellPadding="4">
<SelectedItemStyle Font-Size="XX-Small" Font-Bold="True"
ForeColor="White" BackColor="#000099"></SelectedItemStyle>
<EditItemStyle Font-Size="XX-Small"></EditItemStyle>
<AlternatingItemStyle Font-Size="XX-Small"></AlternatingItemStyle> <ItemStyle Font-Size="XX-Small" BackColor="White"></ItemStyle>
<HeaderStyle Font-Size="XX-Small" Font-Bold="True"

ForeColor="White"
BackColor="Black"></HeaderStyle>
<FooterStyle Font-Size="XX-Small"

BackColor="#CCCCCC"></FooterStyle>
<Columns>
<asp:ButtonColumn Text="Up" ButtonType="PushButton"
CommandName="Up"></asp:ButtonColumn>
<asp:ButtonColumn Text="Down" ButtonType="PushButton"
CommandName="Down"></asp:ButtonColumn>
<asp:EditCommandColumn ButtonType="LinkButton"

UpdateText="Update"
CancelText="Cancel" EditText="Edit">
<HeaderStyle Font-Size="XX-Small"></HeaderStyle>
<ItemStyle Font-Size="XX-Small"></ItemStyle>
<FooterStyle Font-Size="XX-Small"></FooterStyle>
</asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete">
<HeaderStyle Font-Size="XX-Small"></HeaderStyle>
<ItemStyle Font-Size="XX-Small"></ItemStyle>
<FooterStyle Font-Size="XX-Small"></FooterStyle>
</asp:ButtonColumn>
<asp:TemplateColumn HeaderText="Photo">
<ItemTemplate>
<asp:Image runat=server
ImageUrl='<%#ReturnSmallURL(DataBinder.Eval(contai ner.dataitem,

"filename"),
dgAlbums.Items(dgAlbums.SelectedIndex).Cells.Item( 7).Text)%>'

ID="Image2"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Font-Size="XX-Small" HorizontalAlign="Left"
ForeColor="Black" BackColor="#CCCCCC"
Mode="NumericPages"></PagerStyle>
</asp:datagrid>


Nov 18 '05 #3

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

Similar topics

9
by: | last post by:
I have a web page written in asp.net that has multiple datagrids on it that would need to be exported to Excel. Each of the datagrids would be a subset of what the datagrid above it was. Thus...
2
by: mark | last post by:
I have one page with a series of reports to be printed like :- (bear with me ill try to explain the best i can!) report one - checkbox1 report two - checkbox2 report three - checkbox3 and...
0
by: Paul King | last post by:
Hi there, I want to create a page for our site so that our customers can go online and give us feedback. The page will consist namely of text boxes, combo lists and radio buttons. Ive been...
4
by: ree32 | last post by:
I have a placeholder and depending on a user input(a drop downlist) when the user clicks a button I dynamically create a number of datagrids and fill them with data from a database. But the problem...
1
by: Anna | last post by:
Hi there, I have a master/detail page that I've created using a datagrid inside a repeater. I need to find a way to export the entire resulting web page into Excel, and the multiple datagrids...
6
by: Steve Hershoff | last post by:
Hi everyone, I've got a strange one here. There are two datagrids on my page, one nested within the other. I'll refer to them as the topmost and secondary datagrids. In the topmost...
2
by: rn5a | last post by:
In a shopping cart app, a ASPX page retrieves the order details & personal details of a user from a MS-Access database table depending upon the username of the user. The order details of a...
0
by: Jim | last post by:
OK here's my disclaimer: I'm very new to ASP.NET and posting on Google Groups, so please bear with me and feel free to correct either the way I code or the way I post. I have an ASP.NET page...
1
by: =?Utf-8?B?Sm9obiBXYWxrZXI=?= | last post by:
Hi, I am using the code below to export a webpage to Excel. The webpage has three datagrids on it and they are all exported to Excel properly and everything looks very nice, but we would really...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.