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

Datalist with Edit template and custom paging

8
Is it possible to have a Datalist with an Edit mode (<EditItemTemplate />) and custom paging?

I can get <EditItemTemplate> mode and custom paging to work seperately but not together. I can delete a row from the datalist, but once I go into edit mode the UpdateCommand fails. Is this possible because I am going around in circles with postback or not Postback?
Feb 28 '07 #1
4 2293
kenobewan
4,871 Expert 4TB
What error do get? Please post some relevant code.
Mar 1 '07 #2
1333
8
I know the Protected Sub AllPendingImages_UpdateCommand works because when I remove the PAGING code the code fires and the DB gets updated.
When I re-add the paging code and enter edit mode on my page, I think that the id value gets changed to _Page (don't know why) and the update command doesn't fire because the value is not an integer. I have wrapped the code in a Try/Catch but that doesn't throw up any errors - so I'm stuck. Any ideas would be really appreciated, I'm on day 4 looking at it. Thinking about redoing it in a GridView but I prefer the flexibility with the html in a datalist. txs

my aspx page:

Expand|Select|Wrap|Line Numbers
  1. <asp:button id="cmdFirst" runat="server" text="&laquo; First " onclick="cmdFirst_Click" CssClass="button"></asp:button>
  2. <asp:button id="cmdPrev" runat="server" text="&laquo; Back " onclick="cmdPrev_Click" CssClass="button"></asp:button>
  3. <asp:button id="cmdNext" runat="server" text=" Next &raquo; " onclick="cmdNext_Click" CssClass="button"></asp:button>
  4. <asp:button id="cmdLast" runat="server" text=" Last &raquo; " onclick="cmdLast_Click" CssClass="button"></asp:button>
  5.  
  6. <asp:DataList DataKeyField="id" ID="AllPendingImages" runat="server" RepeatColumns="1" RepeatDirection="Horizontal" EnableViewState="false">
  7. <ItemTemplate>
  8. ...
  9. </ItemTemplate>
  10. <EditItemTemplate>
  11. ...
  12. </EditItemTemplate>
  13. </asp:DataList>
Code Behind:

Expand|Select|Wrap|Line Numbers
  1.     Protected WithEvents DDPending As System.Web.UI.WebControls.DropDownList
  2.     Public Property CurrentPage() As Integer
  3.         Get
  4.             Dim o As Object = ViewState("_CurrentPage")
  5.             If (o = Nothing) Then
  6.                 Return 0
  7.             End If
  8.             Return CType(o, Integer)
  9.         End Get
  10.         Set(ByVal value As Integer)
  11.             ViewState("_CurrentPage") = value
  12.         End Set
  13.     End Property
  14.  
  15.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  16.         ItemsGet()
  17.     End Sub
  18.  
  19.     Protected Sub ItemsGet()
  20.         Dim ConnStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
  21.         Dim mySqlConn As New SqlClient.SqlConnection(ConnStr)
  22.         Dim objDA As New SqlDataAdapter("exec sp_GetPendingImages", ConnStr)
  23.         Dim objDS As New DataSet()
  24.         objDA.Fill(objDS)
  25.         mySqlConn.Close()
  26.  
  27.         Dim objPds As PagedDataSource = New PagedDataSource
  28.         objPds.DataSource = objDS.Tables(0).DefaultView
  29.         objPds.AllowPaging = True
  30.         objPds.PageSize = 3
  31.  
  32.         objPds.CurrentPageIndex = CurrentPage
  33.  
  34.         lblCount.Text = ("no of items per page:" + (objPds.Count).ToString + "<br /><br />")
  35.         lblCurrentPageIndex.Text = ("page number:" + (objPds.CurrentPageIndex).ToString + "<br /><br />")
  36.         lblPageCount.Text = ("number of pages:" + (objPds.PageCount).ToString + "<br /><br />")
  37.         lblCurrentPage.Text = ("Page: " + ((CurrentPage + 1).ToString + (" of " + objPds.PageCount.ToString)))
  38.  
  39.         cmdPrev.Enabled = Not objPds.IsFirstPage
  40.         cmdNext.Enabled = Not objPds.IsLastPage
  41.         cmdFirst.Enabled = Not objPds.IsFirstPage
  42.         cmdLast.Enabled = Not objPds.IsLastPage
  43.  
  44.         AllPendingImages.DataSource = objPds
  45.       AllPendingImages.DataBind()
  46.     End Sub
  47.  
  48.     Protected Sub cmdPrev_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  49.         CurrentPage = (CurrentPage - 1)
  50.         ItemsGet()
  51.     End Sub
  52.  
  53.     Protected Sub cmdNext_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  54.          CurrentPage = (CurrentPage + 1)
  55.         ItemsGet()
  56.     End Sub
  57.  
  58.     Protected Sub cmdFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  59.          CurrentPage = 0
  60.         ItemsGet()
  61.     End Sub
  62.  
  63.     Protected Sub cmdLast_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  64.         CurrentPage = (CurrentPage + 2)
  65.         ItemsGet()
  66.     End Sub
  67.  
  68.     Protected Sub AllPendingImages_EditCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles AllPendingImages.EditCommand
  69.         AllPendingImages.EditItemIndex = e.Item.ItemIndex
  70.         ItemsGet()
  71.     End Sub
  72.  
  73.     Protected Sub AllPendingImages_CancelCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles AllPendingImages.CancelCommand
  74.         AllPendingImages.EditItemIndex = -1
  75.          ItemsGet()
  76.     End Sub
  77.  
  78.     Protected Sub AllPendingImages_DeleteCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles AllPendingImages.DeleteCommand
  79. If Page.IsPostBack Then
  80.         Dim id As Integer = Convert.ToInt32(AllPendingImages.DataKeys(e.Item.ItemIndex))
  81.          Dim ConnStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
  82.         Dim mySqlConn As New SqlClient.SqlConnection(ConnStr)
  83.         mySqlConn.Open()
  84.         Dim SQL As String = "sp_DeleteImageRow"
  85.         Dim mySqlCmd As New SqlClient.SqlCommand(SQL, mySqlConn)
  86.         mySqlCmd.CommandType = CommandType.StoredProcedure
  87.         Dim mySqlParamImageID As New SqlClient.SqlParameter("@ImageID", SqlDbType.Int)
  88.         mySqlCmd.Parameters.Add(mySqlParamImageID).Value = id
  89.         mySqlCmd.ExecuteNonQuery()
  90.         mySqlConn.Close()
  91.         AllPendingImages.EditItemIndex = -1
  92.          ItemsGet()
  93. End if
  94.     End Sub
  95.  
  96.     Protected Sub AllPendingImages_UpdateCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles AllPendingImages.UpdateCommand  
  97.      'If Page.IsPostBack Then
  98.     Dim id As Integer = Convert.ToInt32(AllPendingImages.DataKeys(e.Item.ItemIndex))
  99.  
  100.     Dim DDLPending As DropDownList = CType(e.Item.FindControl("DDLPending"), DropDownList)
  101.         Dim Pending As String
  102.         Pending = DDLPending.SelectedValue
  103.  
  104.         Select Case DDLPending.SelectedIndex 'Expression
  105.             Case 0 
  106.                 Pending = 1  'Decline
  107.             Case 1
  108.                 Pending = 2  'Accept
  109.         End Select
  110.  
  111.         Dim PendingValue As String = Nothing
  112.         PendingValue = Pending
  113.  
  114.  
  115.         Dim ConnStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
  116.         Dim mySqlConn As New SqlClient.SqlConnection(ConnStr)
  117.         mySqlConn.Open()
  118.         Dim SQL As String = "sp_UpdatePending"
  119.         Dim mySqlCmd As New SqlClient.SqlCommand(SQL, mySqlConn)
  120.         mySqlCmd.CommandType = CommandType.StoredProcedure
  121.  
  122.         Dim mySqlParamPending As New SqlClient.SqlParameter("@Pending", SqlDbType.Int)
  123.         Dim mySqlParamImageID As New SqlClient.SqlParameter("@ImageID", SqlDbType.Int)
  124.  
  125.         mySqlCmd.Parameters.Add(mySqlParamPending).Value = PendingValue
  126.         mySqlCmd.Parameters.Add(mySqlParamImageID).Value = id
  127.         mySqlCmd.ExecuteNonQuery()
  128.         mySqlConn.Close()
  129.  
  130.         AllPendingImages.EditItemIndex = -1
  131.          ItemsGet()
  132. 'End if
  133.     End Sub
  134.  
  135.  
  136.  
Mar 2 '07 #3
kenobewan
4,871 Expert 4TB
I recall a similar problem I had a year ago. I believe that I copied the paging code into the update command and it worked. So I believe I settled on having a separate sub for paging and referencing that as necessary.

Hope that this helps.
Mar 4 '07 #4
Hi
Thank u ..
I was searching for datalist paging,i tried ur code its working and solved my problem .
I have tried only paging not the "allpendingimages" code
if u get the solution plz forward to me also
my id is

chotu_91@rediffmail.com

Thank u
Archu





I know the Protected Sub AllPendingImages_UpdateCommand works because when I remove the PAGING code the code fires and the DB gets updated.
When I re-add the paging code and enter edit mode on my page, I think that the id value gets changed to _Page (don't know why) and the update command doesn't fire because the value is not an integer. I have wrapped the code in a Try/Catch but that doesn't throw up any errors - so I'm stuck. Any ideas would be really appreciated, I'm on day 4 looking at it. Thinking about redoing it in a GridView but I prefer the flexibility with the html in a datalist. txs

my aspx page:

Expand|Select|Wrap|Line Numbers
  1. <asp:button id="cmdFirst" runat="server" text="&laquo; First " onclick="cmdFirst_Click" CssClass="button"></asp:button>
  2. <asp:button id="cmdPrev" runat="server" text="&laquo; Back " onclick="cmdPrev_Click" CssClass="button"></asp:button>
  3. <asp:button id="cmdNext" runat="server" text=" Next &raquo; " onclick="cmdNext_Click" CssClass="button"></asp:button>
  4. <asp:button id="cmdLast" runat="server" text=" Last &raquo; " onclick="cmdLast_Click" CssClass="button"></asp:button>
  5.  
  6. <asp:DataList DataKeyField="id" ID="AllPendingImages" runat="server" RepeatColumns="1" RepeatDirection="Horizontal" EnableViewState="false">
  7. <ItemTemplate>
  8. ...
  9. </ItemTemplate>
  10. <EditItemTemplate>
  11. ...
  12. </EditItemTemplate>
  13. </asp:DataList>
Code Behind:

Expand|Select|Wrap|Line Numbers
  1.     Protected WithEvents DDPending As System.Web.UI.WebControls.DropDownList
  2.     Public Property CurrentPage() As Integer
  3.         Get
  4.             Dim o As Object = ViewState("_CurrentPage")
  5.             If (o = Nothing) Then
  6.                 Return 0
  7.             End If
  8.             Return CType(o, Integer)
  9.         End Get
  10.         Set(ByVal value As Integer)
  11.             ViewState("_CurrentPage") = value
  12.         End Set
  13.     End Property
  14.  
  15.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  16.         ItemsGet()
  17.     End Sub
  18.  
  19.     Protected Sub ItemsGet()
  20.         Dim ConnStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
  21.         Dim mySqlConn As New SqlClient.SqlConnection(ConnStr)
  22.         Dim objDA As New SqlDataAdapter("exec sp_GetPendingImages", ConnStr)
  23.         Dim objDS As New DataSet()
  24.         objDA.Fill(objDS)
  25.         mySqlConn.Close()
  26.  
  27.         Dim objPds As PagedDataSource = New PagedDataSource
  28.         objPds.DataSource = objDS.Tables(0).DefaultView
  29.         objPds.AllowPaging = True
  30.         objPds.PageSize = 3
  31.  
  32.         objPds.CurrentPageIndex = CurrentPage
  33.  
  34.         lblCount.Text = ("no of items per page:" + (objPds.Count).ToString + "<br /><br />")
  35.         lblCurrentPageIndex.Text = ("page number:" + (objPds.CurrentPageIndex).ToString + "<br /><br />")
  36.         lblPageCount.Text = ("number of pages:" + (objPds.PageCount).ToString + "<br /><br />")
  37.         lblCurrentPage.Text = ("Page: " + ((CurrentPage + 1).ToString + (" of " + objPds.PageCount.ToString)))
  38.  
  39.         cmdPrev.Enabled = Not objPds.IsFirstPage
  40.         cmdNext.Enabled = Not objPds.IsLastPage
  41.         cmdFirst.Enabled = Not objPds.IsFirstPage
  42.         cmdLast.Enabled = Not objPds.IsLastPage
  43.  
  44.         AllPendingImages.DataSource = objPds
  45.       AllPendingImages.DataBind()
  46.     End Sub
  47.  
  48.     Protected Sub cmdPrev_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  49.         CurrentPage = (CurrentPage - 1)
  50.         ItemsGet()
  51.     End Sub
  52.  
  53.     Protected Sub cmdNext_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  54.          CurrentPage = (CurrentPage + 1)
  55.         ItemsGet()
  56.     End Sub
  57.  
  58.     Protected Sub cmdFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  59.          CurrentPage = 0
  60.         ItemsGet()
  61.     End Sub
  62.  
  63.     Protected Sub cmdLast_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  64.         CurrentPage = (CurrentPage + 2)
  65.         ItemsGet()
  66.     End Sub
  67.  
  68.     Protected Sub AllPendingImages_EditCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles AllPendingImages.EditCommand
  69.         AllPendingImages.EditItemIndex = e.Item.ItemIndex
  70.         ItemsGet()
  71.     End Sub
  72.  
  73.     Protected Sub AllPendingImages_CancelCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles AllPendingImages.CancelCommand
  74.         AllPendingImages.EditItemIndex = -1
  75.          ItemsGet()
  76.     End Sub
  77.  
  78.     Protected Sub AllPendingImages_DeleteCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles AllPendingImages.DeleteCommand
  79. If Page.IsPostBack Then
  80.         Dim id As Integer = Convert.ToInt32(AllPendingImages.DataKeys(e.Item.ItemIndex))
  81.          Dim ConnStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
  82.         Dim mySqlConn As New SqlClient.SqlConnection(ConnStr)
  83.         mySqlConn.Open()
  84.         Dim SQL As String = "sp_DeleteImageRow"
  85.         Dim mySqlCmd As New SqlClient.SqlCommand(SQL, mySqlConn)
  86.         mySqlCmd.CommandType = CommandType.StoredProcedure
  87.         Dim mySqlParamImageID As New SqlClient.SqlParameter("@ImageID", SqlDbType.Int)
  88.         mySqlCmd.Parameters.Add(mySqlParamImageID).Value = id
  89.         mySqlCmd.ExecuteNonQuery()
  90.         mySqlConn.Close()
  91.         AllPendingImages.EditItemIndex = -1
  92.          ItemsGet()
  93. End if
  94.     End Sub
  95.  
  96.     Protected Sub AllPendingImages_UpdateCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles AllPendingImages.UpdateCommand  
  97.      'If Page.IsPostBack Then
  98.     Dim id As Integer = Convert.ToInt32(AllPendingImages.DataKeys(e.Item.ItemIndex))
  99.  
  100.     Dim DDLPending As DropDownList = CType(e.Item.FindControl("DDLPending"), DropDownList)
  101.         Dim Pending As String
  102.         Pending = DDLPending.SelectedValue
  103.  
  104.         Select Case DDLPending.SelectedIndex 'Expression
  105.             Case 0 
  106.                 Pending = 1  'Decline
  107.             Case 1
  108.                 Pending = 2  'Accept
  109.         End Select
  110.  
  111.         Dim PendingValue As String = Nothing
  112.         PendingValue = Pending
  113.  
  114.  
  115.         Dim ConnStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
  116.         Dim mySqlConn As New SqlClient.SqlConnection(ConnStr)
  117.         mySqlConn.Open()
  118.         Dim SQL As String = "sp_UpdatePending"
  119.         Dim mySqlCmd As New SqlClient.SqlCommand(SQL, mySqlConn)
  120.         mySqlCmd.CommandType = CommandType.StoredProcedure
  121.  
  122.         Dim mySqlParamPending As New SqlClient.SqlParameter("@Pending", SqlDbType.Int)
  123.         Dim mySqlParamImageID As New SqlClient.SqlParameter("@ImageID", SqlDbType.Int)
  124.  
  125.         mySqlCmd.Parameters.Add(mySqlParamPending).Value = PendingValue
  126.         mySqlCmd.Parameters.Add(mySqlParamImageID).Value = id
  127.         mySqlCmd.ExecuteNonQuery()
  128.         mySqlConn.Close()
  129.  
  130.         AllPendingImages.EditItemIndex = -1
  131.          ItemsGet()
  132. 'End if
  133.     End Sub
  134.  
  135.  
  136.  
Aug 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Fabrizio | last post by:
Hi, I'm trying to create a page with a datalist that loads from a template the ItemTemplate, which contains a linkbutton that should have the commandname = "edit" But when I click on the link...
3
by: moondaddy | last post by:
using vb.net 1.1 I have a datalist and in it's item template I have 2 buttons, 'edit' and 'ShipToThisAddress'. The edit button works fine and it opens up the edit template as it works with the...
3
by: Clint | last post by:
Hi, I am trying to implement the custom paging in the datalist in this format: << Prev 1,2,3,4,5 Next >>. Does anyone knows how to do this. Thanks in advance. Clint
0
by: Isz | last post by:
PROBLEM: This problem is related to the postback and handling events correctly. BACKGROUND: I have a datalist which acts as a tabbes list with horizontal layout. This datalist is bound to a...
3
by: Mirek Endys | last post by:
I have DataList as part of DataList item. DataList in DataList. The parent DataList working well including Edit command, that shows Edit template and correctly bind the data into edit template...
1
by: Chris | last post by:
I want to use the datalist to show a formatted data. I can use the item template to have an image to the left a bit of text to right etc. I would like the ability to add paging. This only seems...
0
by: | last post by:
I'm interested in paging a ASP.NET datalist. The ASP.NET datalist control does not natively support paging. I am binding an XmlDataSource (which is populated by entries in the filesystem) to the...
6
by: Victor | last post by:
Hi. all I have a customize web control. I have three simple properties and customized render class. then I add this control into my datalist like <asp:DataList ID="datalist" runat="server"...
3
by: Crazy Cat | last post by:
Hi all, I am developing an asp.net 2.0 application in Visual Studio 2005. On my page I have a simple datalist that is bound programmatically to a collection of simple objects. On this page I...
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:
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: 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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.