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?
4 2241
What error do get? Please post some relevant code.
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: - <asp:button id="cmdFirst" runat="server" text="« First " onclick="cmdFirst_Click" CssClass="button"></asp:button>
-
<asp:button id="cmdPrev" runat="server" text="« Back " onclick="cmdPrev_Click" CssClass="button"></asp:button>
-
<asp:button id="cmdNext" runat="server" text=" Next » " onclick="cmdNext_Click" CssClass="button"></asp:button>
-
<asp:button id="cmdLast" runat="server" text=" Last » " onclick="cmdLast_Click" CssClass="button"></asp:button>
-
-
<asp:DataList DataKeyField="id" ID="AllPendingImages" runat="server" RepeatColumns="1" RepeatDirection="Horizontal" EnableViewState="false">
-
<ItemTemplate>
-
...
-
</ItemTemplate>
-
<EditItemTemplate>
-
...
-
</EditItemTemplate>
-
</asp:DataList>
Code Behind: -
Protected WithEvents DDPending As System.Web.UI.WebControls.DropDownList
-
Public Property CurrentPage() As Integer
-
Get
-
Dim o As Object = ViewState("_CurrentPage")
-
If (o = Nothing) Then
-
Return 0
-
End If
-
Return CType(o, Integer)
-
End Get
-
Set(ByVal value As Integer)
-
ViewState("_CurrentPage") = value
-
End Set
-
End Property
-
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
ItemsGet()
-
End Sub
-
-
Protected Sub ItemsGet()
-
Dim ConnStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
-
Dim mySqlConn As New SqlClient.SqlConnection(ConnStr)
-
Dim objDA As New SqlDataAdapter("exec sp_GetPendingImages", ConnStr)
-
Dim objDS As New DataSet()
-
objDA.Fill(objDS)
-
mySqlConn.Close()
-
-
Dim objPds As PagedDataSource = New PagedDataSource
-
objPds.DataSource = objDS.Tables(0).DefaultView
-
objPds.AllowPaging = True
-
objPds.PageSize = 3
-
-
objPds.CurrentPageIndex = CurrentPage
-
-
lblCount.Text = ("no of items per page:" + (objPds.Count).ToString + "<br /><br />")
-
lblCurrentPageIndex.Text = ("page number:" + (objPds.CurrentPageIndex).ToString + "<br /><br />")
-
lblPageCount.Text = ("number of pages:" + (objPds.PageCount).ToString + "<br /><br />")
-
lblCurrentPage.Text = ("Page: " + ((CurrentPage + 1).ToString + (" of " + objPds.PageCount.ToString)))
-
-
cmdPrev.Enabled = Not objPds.IsFirstPage
-
cmdNext.Enabled = Not objPds.IsLastPage
-
cmdFirst.Enabled = Not objPds.IsFirstPage
-
cmdLast.Enabled = Not objPds.IsLastPage
-
-
AllPendingImages.DataSource = objPds
-
AllPendingImages.DataBind()
-
End Sub
-
-
Protected Sub cmdPrev_Click(ByVal sender As Object, ByVal e As System.EventArgs)
-
CurrentPage = (CurrentPage - 1)
-
ItemsGet()
-
End Sub
-
-
Protected Sub cmdNext_Click(ByVal sender As Object, ByVal e As System.EventArgs)
-
CurrentPage = (CurrentPage + 1)
-
ItemsGet()
-
End Sub
-
-
Protected Sub cmdFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs)
-
CurrentPage = 0
-
ItemsGet()
-
End Sub
-
-
Protected Sub cmdLast_Click(ByVal sender As Object, ByVal e As System.EventArgs)
-
CurrentPage = (CurrentPage + 2)
-
ItemsGet()
-
End Sub
-
-
Protected Sub AllPendingImages_EditCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles AllPendingImages.EditCommand
-
AllPendingImages.EditItemIndex = e.Item.ItemIndex
-
ItemsGet()
-
End Sub
-
-
Protected Sub AllPendingImages_CancelCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles AllPendingImages.CancelCommand
-
AllPendingImages.EditItemIndex = -1
-
ItemsGet()
-
End Sub
-
-
Protected Sub AllPendingImages_DeleteCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles AllPendingImages.DeleteCommand
-
If Page.IsPostBack Then
-
Dim id As Integer = Convert.ToInt32(AllPendingImages.DataKeys(e.Item.ItemIndex))
-
Dim ConnStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
-
Dim mySqlConn As New SqlClient.SqlConnection(ConnStr)
-
mySqlConn.Open()
-
Dim SQL As String = "sp_DeleteImageRow"
-
Dim mySqlCmd As New SqlClient.SqlCommand(SQL, mySqlConn)
-
mySqlCmd.CommandType = CommandType.StoredProcedure
-
Dim mySqlParamImageID As New SqlClient.SqlParameter("@ImageID", SqlDbType.Int)
-
mySqlCmd.Parameters.Add(mySqlParamImageID).Value = id
-
mySqlCmd.ExecuteNonQuery()
-
mySqlConn.Close()
-
AllPendingImages.EditItemIndex = -1
-
ItemsGet()
-
End if
-
End Sub
-
-
Protected Sub AllPendingImages_UpdateCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles AllPendingImages.UpdateCommand
-
'If Page.IsPostBack Then
-
Dim id As Integer = Convert.ToInt32(AllPendingImages.DataKeys(e.Item.ItemIndex))
-
-
Dim DDLPending As DropDownList = CType(e.Item.FindControl("DDLPending"), DropDownList)
-
Dim Pending As String
-
Pending = DDLPending.SelectedValue
-
-
Select Case DDLPending.SelectedIndex 'Expression
-
Case 0
-
Pending = 1 'Decline
-
Case 1
-
Pending = 2 'Accept
-
End Select
-
-
Dim PendingValue As String = Nothing
-
PendingValue = Pending
-
-
-
Dim ConnStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
-
Dim mySqlConn As New SqlClient.SqlConnection(ConnStr)
-
mySqlConn.Open()
-
Dim SQL As String = "sp_UpdatePending"
-
Dim mySqlCmd As New SqlClient.SqlCommand(SQL, mySqlConn)
-
mySqlCmd.CommandType = CommandType.StoredProcedure
-
-
Dim mySqlParamPending As New SqlClient.SqlParameter("@Pending", SqlDbType.Int)
-
Dim mySqlParamImageID As New SqlClient.SqlParameter("@ImageID", SqlDbType.Int)
-
-
mySqlCmd.Parameters.Add(mySqlParamPending).Value = PendingValue
-
mySqlCmd.Parameters.Add(mySqlParamImageID).Value = id
-
mySqlCmd.ExecuteNonQuery()
-
mySqlConn.Close()
-
-
AllPendingImages.EditItemIndex = -1
-
ItemsGet()
-
'End if
-
End Sub
-
-
-
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.
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: - <asp:button id="cmdFirst" runat="server" text="« First " onclick="cmdFirst_Click" CssClass="button"></asp:button>
-
<asp:button id="cmdPrev" runat="server" text="« Back " onclick="cmdPrev_Click" CssClass="button"></asp:button>
-
<asp:button id="cmdNext" runat="server" text=" Next » " onclick="cmdNext_Click" CssClass="button"></asp:button>
-
<asp:button id="cmdLast" runat="server" text=" Last » " onclick="cmdLast_Click" CssClass="button"></asp:button>
-
-
<asp:DataList DataKeyField="id" ID="AllPendingImages" runat="server" RepeatColumns="1" RepeatDirection="Horizontal" EnableViewState="false">
-
<ItemTemplate>
-
...
-
</ItemTemplate>
-
<EditItemTemplate>
-
...
-
</EditItemTemplate>
-
</asp:DataList>
Code Behind: -
Protected WithEvents DDPending As System.Web.UI.WebControls.DropDownList
-
Public Property CurrentPage() As Integer
-
Get
-
Dim o As Object = ViewState("_CurrentPage")
-
If (o = Nothing) Then
-
Return 0
-
End If
-
Return CType(o, Integer)
-
End Get
-
Set(ByVal value As Integer)
-
ViewState("_CurrentPage") = value
-
End Set
-
End Property
-
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
ItemsGet()
-
End Sub
-
-
Protected Sub ItemsGet()
-
Dim ConnStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
-
Dim mySqlConn As New SqlClient.SqlConnection(ConnStr)
-
Dim objDA As New SqlDataAdapter("exec sp_GetPendingImages", ConnStr)
-
Dim objDS As New DataSet()
-
objDA.Fill(objDS)
-
mySqlConn.Close()
-
-
Dim objPds As PagedDataSource = New PagedDataSource
-
objPds.DataSource = objDS.Tables(0).DefaultView
-
objPds.AllowPaging = True
-
objPds.PageSize = 3
-
-
objPds.CurrentPageIndex = CurrentPage
-
-
lblCount.Text = ("no of items per page:" + (objPds.Count).ToString + "<br /><br />")
-
lblCurrentPageIndex.Text = ("page number:" + (objPds.CurrentPageIndex).ToString + "<br /><br />")
-
lblPageCount.Text = ("number of pages:" + (objPds.PageCount).ToString + "<br /><br />")
-
lblCurrentPage.Text = ("Page: " + ((CurrentPage + 1).ToString + (" of " + objPds.PageCount.ToString)))
-
-
cmdPrev.Enabled = Not objPds.IsFirstPage
-
cmdNext.Enabled = Not objPds.IsLastPage
-
cmdFirst.Enabled = Not objPds.IsFirstPage
-
cmdLast.Enabled = Not objPds.IsLastPage
-
-
AllPendingImages.DataSource = objPds
-
AllPendingImages.DataBind()
-
End Sub
-
-
Protected Sub cmdPrev_Click(ByVal sender As Object, ByVal e As System.EventArgs)
-
CurrentPage = (CurrentPage - 1)
-
ItemsGet()
-
End Sub
-
-
Protected Sub cmdNext_Click(ByVal sender As Object, ByVal e As System.EventArgs)
-
CurrentPage = (CurrentPage + 1)
-
ItemsGet()
-
End Sub
-
-
Protected Sub cmdFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs)
-
CurrentPage = 0
-
ItemsGet()
-
End Sub
-
-
Protected Sub cmdLast_Click(ByVal sender As Object, ByVal e As System.EventArgs)
-
CurrentPage = (CurrentPage + 2)
-
ItemsGet()
-
End Sub
-
-
Protected Sub AllPendingImages_EditCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles AllPendingImages.EditCommand
-
AllPendingImages.EditItemIndex = e.Item.ItemIndex
-
ItemsGet()
-
End Sub
-
-
Protected Sub AllPendingImages_CancelCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles AllPendingImages.CancelCommand
-
AllPendingImages.EditItemIndex = -1
-
ItemsGet()
-
End Sub
-
-
Protected Sub AllPendingImages_DeleteCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles AllPendingImages.DeleteCommand
-
If Page.IsPostBack Then
-
Dim id As Integer = Convert.ToInt32(AllPendingImages.DataKeys(e.Item.ItemIndex))
-
Dim ConnStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
-
Dim mySqlConn As New SqlClient.SqlConnection(ConnStr)
-
mySqlConn.Open()
-
Dim SQL As String = "sp_DeleteImageRow"
-
Dim mySqlCmd As New SqlClient.SqlCommand(SQL, mySqlConn)
-
mySqlCmd.CommandType = CommandType.StoredProcedure
-
Dim mySqlParamImageID As New SqlClient.SqlParameter("@ImageID", SqlDbType.Int)
-
mySqlCmd.Parameters.Add(mySqlParamImageID).Value = id
-
mySqlCmd.ExecuteNonQuery()
-
mySqlConn.Close()
-
AllPendingImages.EditItemIndex = -1
-
ItemsGet()
-
End if
-
End Sub
-
-
Protected Sub AllPendingImages_UpdateCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles AllPendingImages.UpdateCommand
-
'If Page.IsPostBack Then
-
Dim id As Integer = Convert.ToInt32(AllPendingImages.DataKeys(e.Item.ItemIndex))
-
-
Dim DDLPending As DropDownList = CType(e.Item.FindControl("DDLPending"), DropDownList)
-
Dim Pending As String
-
Pending = DDLPending.SelectedValue
-
-
Select Case DDLPending.SelectedIndex 'Expression
-
Case 0
-
Pending = 1 'Decline
-
Case 1
-
Pending = 2 'Accept
-
End Select
-
-
Dim PendingValue As String = Nothing
-
PendingValue = Pending
-
-
-
Dim ConnStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
-
Dim mySqlConn As New SqlClient.SqlConnection(ConnStr)
-
mySqlConn.Open()
-
Dim SQL As String = "sp_UpdatePending"
-
Dim mySqlCmd As New SqlClient.SqlCommand(SQL, mySqlConn)
-
mySqlCmd.CommandType = CommandType.StoredProcedure
-
-
Dim mySqlParamPending As New SqlClient.SqlParameter("@Pending", SqlDbType.Int)
-
Dim mySqlParamImageID As New SqlClient.SqlParameter("@ImageID", SqlDbType.Int)
-
-
mySqlCmd.Parameters.Add(mySqlParamPending).Value = PendingValue
-
mySqlCmd.Parameters.Add(mySqlParamImageID).Value = id
-
mySqlCmd.ExecuteNonQuery()
-
mySqlConn.Close()
-
-
AllPendingImages.EditItemIndex = -1
-
ItemsGet()
-
'End if
-
End Sub
-
-
-
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
3 posts
views
Thread by Fabrizio |
last post: by
|
3 posts
views
Thread by moondaddy |
last post: by
|
3 posts
views
Thread by Clint |
last post: by
|
reply
views
Thread by Isz |
last post: by
|
3 posts
views
Thread by Mirek Endys |
last post: by
|
1 post
views
Thread by Chris |
last post: by
|
reply
views
Thread by |
last post: by
|
6 posts
views
Thread by Victor |
last post: by
|
3 posts
views
Thread by Crazy Cat |
last post: by
| | | | | | | | | | |