#aspx
<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CssClass="table table-hover table-striped" ShowFooter="true" PageSize="15" DataKeyNames="tahun,bulan">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Email" HeaderText="Email" />
<asp:TemplateField HeaderText="Total Account">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" ToolTip="Show Detail" CommandName="ShowAccount"
CommandArgument='<%#Eval("UserId") %>' Text='<%# Eval("total_Account") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Lead">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" ToolTip="Total Lead" CommandName="ShowLead"
CommandArgument='<%#Eval("UserId") %>' Text='<%# Eval("total_Lead") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Owner">
<ItemTemplate>
<asp:LinkButton ID="LinkButton3" runat="server" ToolTip="Total Owner" CommandName="ShowOwner"
CommandArgument='<%#Eval("UserId") %>' Text='<%# Eval("total_owner") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Activity">
<ItemTemplate>
<asp:LinkButton ID="LinkButton4" runat="server" ToolTip="Total Activity" CommandName="ShowActivity"
CommandArgument='<%#Eval("UserId") %>' Text='<%# Eval("total_activity") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Deal">
<ItemTemplate>
<asp:LinkButton ID="LinkButton5" runat="server" ToolTip="Total Deal" CommandName="ShowDeal"
Text='<%# Eval("total_deal") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="tahun" HeaderText="Tahun" />
<asp:BoundField DataField="bulan" HeaderText="Bulan" />
</Columns>
<EmptyDataRowStyle ForeColor="Red" />
<EmptyDataTemplate>
No Record Available
</EmptyDataTemplate>
<PagerStyle />
</asp:GridView>
#codebehind
Protected Sub GridView2_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles GridView2.PageIndexChanging
GridView2.PageIndex = e.NewPageIndex
Me.ShowGrid2()
End Sub
Private Sub ShowGrid2()
Dim cmd As New SqlCommand()
Dim adapter As New SqlDataAdapter()
Dim ds As New DataSet()
Dim i As Integer = 0
Dim sql As String = Nothing
con.Open()
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "ShowTotalSummaries"
cmd.Parameters.Add("@userID", SqlDbType.VarChar).Value = Session("userID")
cmd.Parameters.Add("@Month", SqlDbType.Int).Value = Month.Text
cmd.Parameters.Add("@Year", SqlDbType.Int).Value = Year.Text
adapter = New SqlDataAdapter(cmd)
adapter.Fill(ds)
con.Close()
GridView2.DataSource = ds.Tables(0)
GridView2.DataBind()
End Sub
Protected Sub GridView2_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles GridView2.RowCommand
Dim ctl As Control = TryCast(e.CommandSource, Control)
Dim CurrentRow As GridViewRow = TryCast(ctl.NamingContainer, GridViewRow)
Dim thn As Integer = GridView2.DataKeys(CurrentRow.RowIndex)(0)
Dim bln As Integer = GridView2.DataKeys(CurrentRow.RowIndex)(1)
If e.CommandName = "ShowAccount" Then
Dim id As String = e.CommandArgument.ToString
'tampil grid
Dim cmd As New SqlCommand()
Dim adapter As New SqlDataAdapter()
Dim ds As New DataSet()
Dim i As Integer = 0
Dim sql As String = Nothing
con.Open()
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "ShowTotalAccount"
cmd.Parameters.Add("@Id", SqlDbType.Int).Value = id
' @year int, @month int
cmd.Parameters.Add("@year", SqlDbType.Int).Value = thn
cmd.Parameters.Add("@month", SqlDbType.Int).Value = bln
' cmd.Parameters.AddWithValue("@id_customer_info", Integer.Parse(lblCustomerID.Text.Trim))
adapter = New SqlDataAdapter(cmd)
adapter.Fill(ds)
con.Close()
GridView3.DataSource = ds.Tables(0)
GridView3.DataBind()
ElseIf e.CommandName = "ShowLead" Then
Dim id As String = e.CommandArgument.ToString
'tampil grid
Dim cmd As New SqlCommand()
Dim adapter As New SqlDataAdapter()
Dim ds As New DataSet()
Dim i As Integer = 0
Dim sql As String = Nothing
con.Open()
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "ShowTotalLead"
cmd.Parameters.Add("@Id", SqlDbType.Int).Value = id
cmd.Parameters.Add("@year", SqlDbType.Int).Value = thn
cmd.Parameters.Add("@month", SqlDbType.Int).Value = bln
' cmd.Parameters.AddWithValue("@id_customer_info", Integer.Parse(lblCustomerID.Text.Trim))
adapter = New SqlDataAdapter(cmd)
adapter.Fill(ds)
con.Close()
GridView3.DataSource = ds.Tables(0)
GridView3.DataBind()
ElseIf e.CommandName = "ShowOwner" Then
Dim id As String = e.CommandArgument.ToString
'tampil grid
Dim cmd As New SqlCommand()
Dim adapter As New SqlDataAdapter()
Dim ds As New DataSet()
Dim i As Integer = 0
Dim sql As String = Nothing
con.Open()
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "ShowTotalOwner"
cmd.Parameters.Add("@Id", SqlDbType.Int).Value = id
cmd.Parameters.Add("@year", SqlDbType.Int).Value = thn
cmd.Parameters.Add("@month", SqlDbType.Int).Value = bln
' cmd.Parameters.AddWithValue("@id_customer_info", Integer.Parse(lblCustomerID.Text.Trim))
adapter = New SqlDataAdapter(cmd)
adapter.Fill(ds)
con.Close()
GridView3.DataSource = ds.Tables(0)
GridView3.DataBind()
GridView3.DataBind()
ElseIf e.CommandName = "ShowActivity" Then
Response.Write("<script language=javascript>alert('ERROR ShowActivity');</script>")
ElseIf e.CommandName = "ShowDeal"
Response.Write("<script language=javascript>alert('ERROR ShowDeal');</script>")
End If
End Sub
that's my source code above.. and messege error in previous page or second page :
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error:
Line 108: Dim ctl As Control = TryCast(e.CommandSource, Control)
Line 109: Dim CurrentRow As GridViewRow = TryCast(ctl.NamingContainer, GridViewRow)
Line 110: Dim thn As Integer = GridView2.DataKeys(CurrentRow.RowIndex)(0)
Line 111: Dim bln As Integer = GridView2.DataKeys(CurrentRow.RowIndex)(1)
Line 112:
|