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 2293
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
-
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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"...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
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...
|
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: 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...
|
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,...
| |