Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

i need to do paging in gridview inside datalist ..?

Posted on 2009-07-10
3
Medium Priority
?
719 Views
Last Modified: 2013-11-07
i dunno how to pass the label text of datalist  to bind function in the pageindexchanging of grid view ..plz suggest.....and also having no idea of paging for this datalist which have page size of five?

Protected Sub pageindexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
        Dim grid As GridView = DirectCast(sender, GridView)
        grid.PageIndex = e.NewPageIndex
        Dim name As String = ??'how can i pass the label of text property of Datalist which has this gridview.in order to bind for the next page...??
        BindGrid(grid, name)
    End Sub
Private Sub BindGrid(ByVal GridView As GridView, ByVal name As String)
        Dim con As SqlConnection
       con = New SqlConnection(ConfigurationSettings.AppSettings("cons"))
        Dim Sql1 As String = "select * from tbl1 where name ='"& name &"'
        Dim da As New SqlDataAdapter(Sql1, con)
        Dim ds As New DataSet()
        da.Fill(ds)
       GridView.DataSource = ds
        GridView.DataBind()
End If
 End Sub
 
Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)
        Dim GridView1 As GridView = DirectCast(e.Item.FindControl("GridView1"), GridView)
        Dim name As Label = TryCast(e.Item.FindControl("name"), Label)
        BindGrid(GridView1, name.Text)
    End Sub
 
 
<asp:DataList ID="DataList1"  runat="server"  OnItemDataBound="DataList1_ItemDataBound" Width="350px">
<ItemTemplate>          
<asp:Label ID="name" runat="server" Visible="false" Text='<%# Bind("name") %>'></asp:Label>
<asp:GridView ID="GridView1" AllowPaging="true" OnPageIndexChanging="pageindexChanging" PageSize="5"  runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="name" HeaderText="Name" ></asp:BoundField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:DataList>

Open in new window

0
Comment
Question by:Rajar Ahmed
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
jinal earned 2000 total points
ID: 24821307
Hello,
This sample help you.

/* ASPX CODE */ 
<asp:DataList ID="DataList1"  runat="server"  OnItemDataBound="DataList1_ItemDataBound" Width="350px">
<ItemTemplate>          
<asp:Label ID="name" runat="server" Visible="false" Text='<%# Bind("name") %>'></asp:Label>
<asp:Label ID="ID" runat="server" Visible="false" Text='<%# Bind("ID") %>'></asp:Label>
<asp:GridView ID="GridView1" AllowPaging="true" OnPageIndexChanging="pageindexChanging" PageSize="5"  runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="productname" HeaderText="Name" ></asp:BoundField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:DataList>
 
/* Code Behind File */
 
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Data
Partial Class _Default
    Inherits System.Web.UI.Page
    Private Sub BindGrid(ByVal GridView As GridView, ByVal name As String)
        Dim con As SqlConnection
        con = New SqlConnection("Data Source=ANKIT\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True")
        Dim Sql1 As String = "select * from products where CategoryID =" & name & ""
        Dim da As New SqlDataAdapter(Sql1, con)
        Dim ds As New DataSet()
        da.Fill(ds)
 
        GridView.DataSource = ds.Tables(0)
        GridView.DataBind()
        
 
    End Sub
    Private Sub BindGridWithPageIndex(ByVal GridView As GridView, ByVal name As String, ByVal pageIndex As Integer)
        Dim con As SqlConnection
        con = New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True")
        Dim Sql1 As String = "select * from products where CategoryID =" & name & ""
        Dim da As New SqlDataAdapter(Sql1, con)
        Dim ds As New DataSet()
        da.Fill(ds)
        GridView.PageIndex = pageIndex
        GridView.DataSource = ds.Tables(0)
        GridView.DataBind()
 
 
    End Sub
 
    Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)
        Dim GridView1 As GridView = DirectCast(e.Item.FindControl("GridView1"), GridView)
        Dim name As Label = TryCast(e.Item.FindControl("ID"), Label)
        BindGrid(GridView1, name.Text)
    End Sub
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Dim dt As New DataTable()
            dt.Columns.Add("Name")
            dt.Columns.Add("Id")
            Dim dr As DataRow
            dr = dt.NewRow()
            dr(0) = "Beverages"
            dr(1) = "1"
            dt.Rows.Add(dr)
 
            dr = dt.NewRow()
            dr(0) = "Condiments"
            dr(1) = "2"
            dt.Rows.Add(dr)
 
            DataList1.DataSource = dt
            DataList1.DataBind()
 
        End If
    End Sub
 
    Protected Sub pageindexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
        Dim gv As GridView = CType(sender, GridView)
        If Not gv Is Nothing Then
            Dim lb As Label = CType(gv.Parent.FindControl("ID"), Label)
            BindGridWithPageIndex(CType(sender, GridView), lb.Text, e.NewPageIndex)
        End If
    End Sub
End Class

Open in new window

0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 24821440
hi this line did the trick..
can u suggest how to do the paging for this datalist  ,,,?

        Dim lb As Label = CType(grid.Parent.FindControl("name"), Label)

Open in new window

0
 
LVL 15

Assisted Solution

by:jinal
jinal earned 2000 total points
ID: 24821992
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question