J
JasonK68
Guest
Hi,
I am a bit new to ASP.NET and VB but I have been trying to find a solution to this for a couple of days already. I am continuing the coding work for a colleague of mine so many of the code is still new to me. We use Microsoft Visual Studio 2010 and I am coding in a localhost. I believe the code is correct but for some reason, the Select button from the gridview table does nothing! It does not select the row as I want it to, I am sure that nothing is selected because I have tested this with setting the SelectedIndex to more than -1 and changing the SelectedRowStyle to a different backcolor, once I select on other rows Select button, nothing happens. My primary goal from this is to be able to select the row. Once selected, I would need to find a way to take the values in the corresponding columns and place them in the text boxes labelled txtID and txtDivision.
I believe part of the issue lies in the linked URL path for these Select buttons. When I roll over the Select button, it shows the path of: Javascript:_doPostBack(‘ctl00$MainContent$gridview1’,’Select$1’)
Im unsure where that path comes from or where it is linked to, but could that be the issue? I understand that you would need to see the front end page code and behind code.
Please find below the front end page code for the file frmDivision.aspx: (Please note that the Subs in the script tags were failed tests because ironically, no selections can be made, however without these Sub scripts I would get a different error stating that the used SelectedIndexChanged and SelectedIndexChanging is not a member of my file. The error message is: "BC30456: gridview1_SelectedIndexChanged is not a member of ASP.frmdivision_aspx")
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="frmDivision.aspx.vb" Inherits="HRApplication.WebForm2" %>
<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server
<script src="Scripts/jsPreviewReport.js" type="text/javascript </script>
</asp:Content>
<script runat="server
Sub gridview1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim row As GridViewRow = gridview1.SelectedRow
Dim MessageLabel, Message
MessageLabel.Text = "You selected " & row.Cells(2).Text & "."
Dim txtID As String = row.Cells(1).Text
Dim DivisionLiteral As DataBoundLiteralControl = CType(row.Cells(2).Controls(0), DataBoundLiteralControl)
Dim txtDivision As String = row.Cells(2).Text
Message.Text = "You selected " & txtID & " " & txtDivision & "."
End Sub
Sub gridview1_SelectedIndexChanging(ByVal sender As Object, ByVal e As GridViewSelectEventArgs)
Dim row As GridViewRow = gridview1.Rows(e.NewSelectedIndex)
End Sub
</script>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server
<table>
<tr><td><asp:Label ID="lblID" runat="server" Text="ID </asp:Label></td><td>
<asp:TextBox ID="txtID" runat="server" Text=" </asp:TextBox></td><td></td></tr>
<tr><td><asp:Label ID="lblDivision" runat="server" Text="Division </asp:Label>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
AutoDataBind="true" />
</td><td>
<asp:TextBox ID="txtDivision" runat="server </asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" /> <asp:Button ID="btnExit" runat="server" Text="Exit" />
<asp:Button ID="btnDelete" runat="server" Text="Delete" Visible="False"
Width="57px" />
<asp:Button ID="btnPrint" runat="server" Text="Print" onclientclick="winopenFindReport(rptDivision.rpt);" style="height: 26px" />
</td></tr>
</table>
<br />
<asp:GridView ID="gridview1" runat="server" Width="690px"
DataKeyNames="ID" AutoGenerateColumns="false" AutoGenerateSelectButton="true"
onselectedindexchanged="gridview1_SelectedIndexChanged" OnSelectedIndexChanging="gridview1_SelectedIndexChanging
<Columns>
<asp:BoundField DataField="ID"
HeaderText="ID"
SortExpression="ID" />
<asp:BoundField DataField="Division"
HeaderText="Division"
SortExpression="Division" />
</Columns>
<SelectedRowStyle BackColor="#0066FF"/>
</asp:GridView>
</asp:Content>
Please find below the relevant behind code in frmDivision.aspx.vb:
Imports System.Web.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class WebForm2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim conn As SqlConnection
Dim strsql, strsql1 As String
Dim cmd As SqlCommand
Dim reader2 As SqlDataReader
If User.Identity.IsAuthenticated Then
Else
Response.Redirect("Account/Login.aspx")
End If
If Not IsPostBack Then
conn = mdlPublicFunction.OpenConnection
strsql1 = "select ID,Division from tbDivision "
cmd = New SqlCommand(strsql1, conn)
reader2 = cmd.ExecuteReader()
If reader2.HasRows Then
gridview1.DataSource = reader2
gridview1.DataBind()
End If
End If
End Sub
Please help with this as I am really stuck! Thank you very much!
Jason
Continue reading...
I am a bit new to ASP.NET and VB but I have been trying to find a solution to this for a couple of days already. I am continuing the coding work for a colleague of mine so many of the code is still new to me. We use Microsoft Visual Studio 2010 and I am coding in a localhost. I believe the code is correct but for some reason, the Select button from the gridview table does nothing! It does not select the row as I want it to, I am sure that nothing is selected because I have tested this with setting the SelectedIndex to more than -1 and changing the SelectedRowStyle to a different backcolor, once I select on other rows Select button, nothing happens. My primary goal from this is to be able to select the row. Once selected, I would need to find a way to take the values in the corresponding columns and place them in the text boxes labelled txtID and txtDivision.
I believe part of the issue lies in the linked URL path for these Select buttons. When I roll over the Select button, it shows the path of: Javascript:_doPostBack(‘ctl00$MainContent$gridview1’,’Select$1’)
Im unsure where that path comes from or where it is linked to, but could that be the issue? I understand that you would need to see the front end page code and behind code.
Please find below the front end page code for the file frmDivision.aspx: (Please note that the Subs in the script tags were failed tests because ironically, no selections can be made, however without these Sub scripts I would get a different error stating that the used SelectedIndexChanged and SelectedIndexChanging is not a member of my file. The error message is: "BC30456: gridview1_SelectedIndexChanged is not a member of ASP.frmdivision_aspx")
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="frmDivision.aspx.vb" Inherits="HRApplication.WebForm2" %>
<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server
<script src="Scripts/jsPreviewReport.js" type="text/javascript </script>
</asp:Content>
<script runat="server
Sub gridview1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim row As GridViewRow = gridview1.SelectedRow
Dim MessageLabel, Message
MessageLabel.Text = "You selected " & row.Cells(2).Text & "."
Dim txtID As String = row.Cells(1).Text
Dim DivisionLiteral As DataBoundLiteralControl = CType(row.Cells(2).Controls(0), DataBoundLiteralControl)
Dim txtDivision As String = row.Cells(2).Text
Message.Text = "You selected " & txtID & " " & txtDivision & "."
End Sub
Sub gridview1_SelectedIndexChanging(ByVal sender As Object, ByVal e As GridViewSelectEventArgs)
Dim row As GridViewRow = gridview1.Rows(e.NewSelectedIndex)
End Sub
</script>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server
<table>
<tr><td><asp:Label ID="lblID" runat="server" Text="ID </asp:Label></td><td>
<asp:TextBox ID="txtID" runat="server" Text=" </asp:TextBox></td><td></td></tr>
<tr><td><asp:Label ID="lblDivision" runat="server" Text="Division </asp:Label>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
AutoDataBind="true" />
</td><td>
<asp:TextBox ID="txtDivision" runat="server </asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" /> <asp:Button ID="btnExit" runat="server" Text="Exit" />
<asp:Button ID="btnDelete" runat="server" Text="Delete" Visible="False"
Width="57px" />
<asp:Button ID="btnPrint" runat="server" Text="Print" onclientclick="winopenFindReport(rptDivision.rpt);" style="height: 26px" />
</td></tr>
</table>
<br />
<asp:GridView ID="gridview1" runat="server" Width="690px"
DataKeyNames="ID" AutoGenerateColumns="false" AutoGenerateSelectButton="true"
onselectedindexchanged="gridview1_SelectedIndexChanged" OnSelectedIndexChanging="gridview1_SelectedIndexChanging
<Columns>
<asp:BoundField DataField="ID"
HeaderText="ID"
SortExpression="ID" />
<asp:BoundField DataField="Division"
HeaderText="Division"
SortExpression="Division" />
</Columns>
<SelectedRowStyle BackColor="#0066FF"/>
</asp:GridView>
</asp:Content>
Please find below the relevant behind code in frmDivision.aspx.vb:
Imports System.Web.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class WebForm2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim conn As SqlConnection
Dim strsql, strsql1 As String
Dim cmd As SqlCommand
Dim reader2 As SqlDataReader
If User.Identity.IsAuthenticated Then
Else
Response.Redirect("Account/Login.aspx")
End If
If Not IsPostBack Then
conn = mdlPublicFunction.OpenConnection
strsql1 = "select ID,Division from tbDivision "
cmd = New SqlCommand(strsql1, conn)
reader2 = cmd.ExecuteReader()
If reader2.HasRows Then
gridview1.DataSource = reader2
gridview1.DataBind()
End If
End If
End Sub
Please help with this as I am really stuck! Thank you very much!
Jason
Continue reading...