Hi
I'm building an application in VS 2005 that uses a dataset to display info with checkboxes which determine what data is displayed after a button click. I think I have something wrong with my code behind and logic, but I'm really stumped and would appreciate any hints/direction help.
My code behind is:
Imports System.Data
Imports System.Configuration
Imports System.Web.UI.WebControls
Imports DataSet1TableAdapters
Namespace DotNetTony
Public Class storylist : Inherits System.Web.UI.Page
Dim btnShow As Button
Dim lblSelections As Label
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
btnShow.Attributes.Add("onClick", "javascript:return confirm('Are you sure you want to delete these rows?')")
BindTheData()
End If
End Sub
Sub BindTheData()
Dim newsAdapter As New Orizonti_NukeNews_NewsTableAdapter
GridView1.DataSource = newsAdapter.GetData()
GridView1.DataBind()
End Sub
Sub ShowSelections(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim dgItem As DataGridItem
Dim chkSelected As CheckBox
Dim strTitle As String
Dim strID As String
Dim strSummary As String
Dim strPostDate As String
lblSelections.Text = "<br>Fooled Ya! The following rows were marked for deletion, "
lblSelections.Text += "but not actually deleted:<br><br>"
For Each dgItem In GridView1.Items
chkSelected = GridView1.FindControl("chkSelection")
If chkSelected.Checked Then
strTitle = CType(dgItem.FindControl("lblTitle"), Label).Text
strSummary = CType(dgItem.FindControl("lblSumamry"), Label).Text
strPostDate = CType(dgItem.FindControl("lblPostDate"), Label).Text
lblSelections.Text += "Title: <b>" & strTitle & "</b> | "
lblSelections.Text += "Summary: <b>" & strSummary & "</b> | "
lblSelections.Text += "Date posted:: <b>" & strPostDate & "</b><br>"
End If
Next
End Sub
End Class
End Namespace
My aspx page is:
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="DotNetTony.storylist" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>View news stories</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:Button ID="btnShow" Text="Delete Checked Rows" OnClick="ShowSelections" Runat="server" />
<div>
<h1>News stories</h1>
<p>
<asp
ataGrid ID="GridView1" runat="server"
AutoGenerateColumns="False"
BorderColor="#999999"
BorderStyle="None"
BorderWidth="1px"
BackColor="White"
CellPadding="3"
GridLines="Vertical">
<Columns>
<asp:TemplateColumn HeaderText="Title">
<ItemTemplate>
<asp:Label ID="lblTitle"
Text='<%# DataBinder.Eval(Container.DataItem,"Title") %>'
runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Summary" DataField="Summary" />
<asp:BoundColumn HeaderText="Date Posted" DataField="PostDate" />
<asp:BoundColumn HeaderText="ID" DataField="ID" Visible="False" />
<asp:TemplateColumn HeaderText="ID" Visible="False">
<ItemTemplate>
<asp:Label ID="lblID"
Text='<%# DataBinder.Eval(Container.DataItem,"ID") %>'
Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Delete" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="chkSelection" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<AlternatingItemStyle BackColor="#DCDCDC" />
<ItemStyle ForeColor="Black" BackColor="#EEEEEE" />
<headerStyle Font-Bold="True" ForeColor="White" BackColor="#000084" />
</asp
ataGrid>
<asp:Label ID="lblSelections"
Runat="server"
Font-Name="Verdana"
Font-Size="10px" />
</asp
ataGrid>
</p>
</div>
</form>
</body>
</html>
I'm building an application in VS 2005 that uses a dataset to display info with checkboxes which determine what data is displayed after a button click. I think I have something wrong with my code behind and logic, but I'm really stumped and would appreciate any hints/direction help.
My code behind is:
Imports System.Data
Imports System.Configuration
Imports System.Web.UI.WebControls
Imports DataSet1TableAdapters
Namespace DotNetTony
Public Class storylist : Inherits System.Web.UI.Page
Dim btnShow As Button
Dim lblSelections As Label
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
btnShow.Attributes.Add("onClick", "javascript:return confirm('Are you sure you want to delete these rows?')")
BindTheData()
End If
End Sub
Sub BindTheData()
Dim newsAdapter As New Orizonti_NukeNews_NewsTableAdapter
GridView1.DataSource = newsAdapter.GetData()
GridView1.DataBind()
End Sub
Sub ShowSelections(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim dgItem As DataGridItem
Dim chkSelected As CheckBox
Dim strTitle As String
Dim strID As String
Dim strSummary As String
Dim strPostDate As String
lblSelections.Text = "<br>Fooled Ya! The following rows were marked for deletion, "
lblSelections.Text += "but not actually deleted:<br><br>"
For Each dgItem In GridView1.Items
chkSelected = GridView1.FindControl("chkSelection")
If chkSelected.Checked Then
strTitle = CType(dgItem.FindControl("lblTitle"), Label).Text
strSummary = CType(dgItem.FindControl("lblSumamry"), Label).Text
strPostDate = CType(dgItem.FindControl("lblPostDate"), Label).Text
lblSelections.Text += "Title: <b>" & strTitle & "</b> | "
lblSelections.Text += "Summary: <b>" & strSummary & "</b> | "
lblSelections.Text += "Date posted:: <b>" & strPostDate & "</b><br>"
End If
Next
End Sub
End Class
End Namespace
My aspx page is:
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="DotNetTony.storylist" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>View news stories</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:Button ID="btnShow" Text="Delete Checked Rows" OnClick="ShowSelections" Runat="server" />
<div>
<h1>News stories</h1>
<p>
<asp

AutoGenerateColumns="False"
BorderColor="#999999"
BorderStyle="None"
BorderWidth="1px"
BackColor="White"
CellPadding="3"
GridLines="Vertical">
<Columns>
<asp:TemplateColumn HeaderText="Title">
<ItemTemplate>
<asp:Label ID="lblTitle"
Text='<%# DataBinder.Eval(Container.DataItem,"Title") %>'
runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Summary" DataField="Summary" />
<asp:BoundColumn HeaderText="Date Posted" DataField="PostDate" />
<asp:BoundColumn HeaderText="ID" DataField="ID" Visible="False" />
<asp:TemplateColumn HeaderText="ID" Visible="False">
<ItemTemplate>
<asp:Label ID="lblID"
Text='<%# DataBinder.Eval(Container.DataItem,"ID") %>'
Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Delete" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="chkSelection" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<AlternatingItemStyle BackColor="#DCDCDC" />
<ItemStyle ForeColor="Black" BackColor="#EEEEEE" />
<headerStyle Font-Bold="True" ForeColor="White" BackColor="#000084" />
</asp

<asp:Label ID="lblSelections"
Runat="server"
Font-Name="Verdana"
Font-Size="10px" />
</asp

</p>
</div>
</form>
</body>
</html>
Comment