Thursday, December 8, 2011

Paging in Gridview If we dont set Datasource

Declare the dataset as
Shared ds as new Dataset

Bind the gridview using dataset as

Gridview1.Datasource = ds.Table(0)
Gridview1.DataBind()

After that make the AllowPaging = True

Then we have to handle  PageIndexChanging event as bel;ow

Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        Try
            GridView1.PageIndex = e.NewPageIndex
            GridView1.DataSource = dsTmp.Tables(0)
            GridView1.DataBind()
        Catch ex As Exception

        End Try
    End Sub

Working with Gridview in ASP.NET

Suppose the gridview contains four columns with the last two column as template with Hyperlink
When I click that Hyperlink I need that value in some where say TextBox


                             
 

and in the code behind GridView1_RowCommand event

If e.CommandName = "claim" Then
            Dim index As Integer = Convert.ToInt32(e.CommandArgument)

            Dim row = GridView1.Rows(index)

            Dim lin As LinkButton = CType(row.FindControl("ClaimLink"), LinkButton)
            Dim lin2 As LinkButton = CType(row.FindControl("TransLink"), LinkButton)

            ClaimID.Text = lin.Text
            TRansID.Text = lin2.Text
End If