What event get triggered when the select button is clicked in the Data Grid server control.
Thanks in advance!!!!!!!
Printable View
What event get triggered when the select button is clicked in the Data Grid server control.
Thanks in advance!!!!!!!
what 'select' button? There nothing called a select button.
Are you referring to a hyperlinkcolumn, buttoncolumn, template column, editcolumn???
ButtonColumn Type=PushButton Name=Select Text=Add
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
Code:Sub Grid_Command(sender As Object, e As DataGridCommandEventArgs)
If e.CommandSource.CommandName = "Select" Then
'Do something
End If
End Sub
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.
can you post your page's code here so I can see..maybe be some minor little thing?
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
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.
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
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:
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I meant for the actual buttoncolumn tag. Did you try that ?:
Yeah, it isn't available for that either.
well doo doo!
Oh well..at least it works the other way..