Results 1 to 14 of 14

Thread: DataGrid in ASP.net

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2000
    Posts
    51

    Smile DataGrid in ASP.net

    What event get triggered when the select button is clicked in the Data Grid server control.

    Thanks in advance!!!!!!!
    Everyone!!! Can I have your attention please?

    Sit back, Relax and watch the world unfold before your very eyes.

    Mystical isn't it, oh well I tried!!!

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    what 'select' button? There nothing called a select button.

    Are you referring to a hyperlinkcolumn, buttoncolumn, template column, editcolumn???
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2000
    Posts
    51
    ButtonColumn Type=PushButton Name=Select Text=Add
    Everyone!!! Can I have your attention please?

    Sit back, Relax and watch the world unfold before your very eyes.

    Mystical isn't it, oh well I tried!!!

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2000
    Posts
    51
    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.
    Everyone!!! Can I have your attention please?

    Sit back, Relax and watch the world unfold before your very eyes.

    Mystical isn't it, oh well I tried!!!

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    can you post your page's code here so I can see..maybe be some minor little thing?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2000
    Posts
    51
    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
    Everyone!!! Can I have your attention please?

    Sit back, Relax and watch the world unfold before your very eyes.

    Mystical isn't it, oh well I tried!!!

  8. #8
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  9. #9

    Thread Starter
    Member
    Join Date
    Dec 2000
    Posts
    51
    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
    Everyone!!! Can I have your attention please?

    Sit back, Relax and watch the world unfold before your very eyes.

    Mystical isn't it, oh well I tried!!!

  10. #10
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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?!?!!?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  11. #11

    Thread Starter
    Member
    Join Date
    Dec 2000
    Posts
    51
    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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Everyone!!! Can I have your attention please?

    Sit back, Relax and watch the world unfold before your very eyes.

    Mystical isn't it, oh well I tried!!!

  12. #12
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    I meant for the actual buttoncolumn tag. Did you try that ?:
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  13. #13

    Thread Starter
    Member
    Join Date
    Dec 2000
    Posts
    51
    Yeah, it isn't available for that either.
    Everyone!!! Can I have your attention please?

    Sit back, Relax and watch the world unfold before your very eyes.

    Mystical isn't it, oh well I tried!!!

  14. #14
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    well doo doo!

    Oh well..at least it works the other way..
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width