Click to See Complete Forum and Search --> : DataGrid in ASP.net
pacman429
Mar 4th, 2002, 03:25 PM
What event get triggered when the select button is clicked in the Data Grid server control.
Thanks in advance!!!!!!!
Cander
Mar 4th, 2002, 03:34 PM
what 'select' button? There nothing called a select button.
Are you referring to a hyperlinkcolumn, buttoncolumn, template column, editcolumn???
pacman429
Mar 4th, 2002, 03:45 PM
ButtonColumn Type=PushButton Name=Select Text=Add
Cander
Mar 4th, 2002, 04:26 PM
ok..its just named select..got ya..here you go
first add this attribute to the datagrid tag
OnItemCommand="Grid_Command"
Grid_Command is the name of the called Sub..you can name it anything else...your choice
add this attribute to your button tag
CommandName="Select"
NMow here is the sub
Sub Grid_Command(sender As Object, e As DataGridCommandEventArgs)
If e.CommandSource.CommandName = "Select" Then
'Do something
End If
End Sub
pacman429
Mar 5th, 2002, 07:28 AM
I did that it doesn't do anything. I put a break on the if statement and attempted to click on the button. The application never reaches that sub.
Cander
Mar 5th, 2002, 08:17 AM
can you post your page's code here so I can see..maybe be some minor little thing?
pacman429
Mar 5th, 2002, 08:45 AM
Here is code in the aspx file:
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 46px; POSITION: absolute; TOP: 90px" runat="server" CellPadding="3" BackColor="#DEBA84" BorderWidth="1px" CellSpacing="2" BorderStyle="None" BorderColor="#DEBA84" AllowPaging="True" PageSize="5" Height="147px" Width="603px" OnItemCommand="DataGrid1_Select" AutoGenerateColumns="False">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#738A9C"></SelectedItemStyle>
<ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#A55129"></HeaderStyle>
<FooterStyle ForeColor="#8C4510" BackColor="#F7DFB5"></FooterStyle>
<Columns>
<asp:ButtonColumn Text="Add" ButtonType="PushButton" HeaderText="Select Report" CommandName="Select" />
<asp:BoundColumn HeaderText="Report ID" DataField="ReportID" />
<asp:BoundColumn HeaderText="Title" DataField="Title" />
<asp:BoundColumn HeaderText="Pages" DataField="Pages" />
<asp:BoundColumn HeaderText="Lines" DataField="Lines" />
<asp:BoundColumn HeaderText="Time" DataField="Time" />
<asp:BoundColumn HeaderText="Date" DataField="Date" />
<asp:BoundColumn HeaderText="Status" DataField="Status" />
<asp:BoundColumn HeaderText="PartitionNum" DataField="PartitionNum" />
<asp:BoundColumn HeaderText="CorpCode" DataField="CorpCode" />
<asp:BoundColumn HeaderText="SubsdCompCode" DataField="SubsdCompCode" />
<asp:BoundColumn HeaderText="OperDivCode" DataField="OperDivCode" />
<asp:BoundColumn HeaderText="StoreDivCode" DataField="StoreDivCode" />
<asp:BoundColumn HeaderText="StoreLeagueCode" DataField="StoreLeagueCode" />
<asp:BoundColumn HeaderText="StoreNum" DataField="StoreNum" />
</Columns>
<PagerStyle HorizontalAlign="Left" ForeColor="#8C4510" PageButtonCount="5" Mode="NumericPages"></PagerStyle>
</asp:datagrid><asp:listbox id="ListBox1" style="Z-INDEX: 102; LEFT: 5px; POSITION: absolute; TOP: 7px" runat="server" Height="72px" Width="390px"></asp:listbox></form>
</body>
Here is the code in the vb file:
Imports System.Data
Public Class WebForm1
Inherits System.Web.UI.Page
Dim DS As New DataSet()
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents ListBox1 As System.Web.UI.WebControls.ListBox
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim A As Integer
DS.ReadXml("D:\Inetpub\WWWRoot\DatarGrid1\GetReports.xml")
Dim Source As DataView
Source = New DataView(DS.Tables(0))
Me.DataGrid1.DataSource = Source
Page.DataBind()
For A = 8 To 14
Me.DataGrid1.Columns(A).Visible = False
Next
End Sub
Private Sub ChangeGridPage(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
Me.DataGrid1.CurrentPageIndex = e.NewPageIndex
Page.DataBind()
End Sub
Public Sub DataGrid1_Select(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
If e.CommandSource.CommandName = "Select" Then
Me.ListBox1.Items.Add("I finally selected a line")
End If
End Sub
End Class
Thanks for you assistance
Cander
Mar 5th, 2002, 08:51 AM
Are any of your procedures being run? I dont see this line specifying what .vb file and class to use with your aspx page for code behind
<%@ Page language="vb" Inherits="WebForm1" SRC="test.vb"%>
that should be at the very top of your aspx page if you dont have it already.
Everything else looks correct so far.
pacman429
Mar 5th, 2002, 09:55 AM
Hey that did it!
I guess there is a bug in the pushbutton. I thought about changing it but never did.
Thanks for your help! I'll try to find a way to report this to MS
Cander
Mar 5th, 2002, 10:00 AM
w00t!
Well you know in after thought..it could be that when using the pushbutton style you may need the On_Click="functiontocall" attribute like with nroaml buttons. Try that too perhaps that is the correct way to do?!?!!?:eek:
pacman429
Mar 5th, 2002, 10:07 AM
I just tried that also but no luck. There is no on_click event for the data grid available only onitemcommand.
thanks for your help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Cander
Mar 5th, 2002, 10:09 AM
I meant for the actual buttoncolumn tag. Did you try that ?:
pacman429
Mar 5th, 2002, 10:12 AM
Yeah, it isn't available for that either.
Cander
Mar 5th, 2002, 10:14 AM
well doo doo!
Oh well..at least it works the other way..
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.