Select Button In Datagrid not working (VS2003/FW1.1)

Discussion in 'ASP .Net Datagrid Control' started by Richard Adams, Jul 17, 2003.

  1. I've got two pages, each displaying a datagrid with a Select button
    column.
    With one the Select command is handled in the codebehind and works
    fine.

    The second page is a very similar setup, but designed after upgrading
    to Visual Studio 2003/Framework 1.1 Select evidently does something,
    but the event handling routine in codebehind doesn't execute. I've
    stripped away almost eveything on the form and even rebuilt the page
    from scratch and the Select button still is not handled.

    Checked document and form properties and all are identical to the
    first page, except meta tags (first page still refers to being created
    in VS.NET 7.0, rather than 7.1)

    Any ideas why the inconsistent behavior? How to see what the browser
    is attempting to send back to the server?

    I'm currently residing at No. 1 Witt's End.

    Richard
     
    Richard Adams, Jul 17, 2003
    #1
    1. Advertising

  2. Are you handling PostBack
    "Richard Adams" <> wrote in message
    news:...
    > I've got two pages, each displaying a datagrid with a Select button
    > column.
    > With one the Select command is handled in the codebehind and works
    > fine.
    >
    > The second page is a very similar setup, but designed after upgrading
    > to Visual Studio 2003/Framework 1.1 Select evidently does something,
    > but the event handling routine in codebehind doesn't execute. I've
    > stripped away almost eveything on the form and even rebuilt the page
    > from scratch and the Select button still is not handled.
    >
    > Checked document and form properties and all are identical to the
    > first page, except meta tags (first page still refers to being created
    > in VS.NET 7.0, rather than 7.1)
    >
    > Any ideas why the inconsistent behavior? How to see what the browser
    > is attempting to send back to the server?
    >
    > I'm currently residing at No. 1 Witt's End.
    >
    > Richard
     
    Sonali.NET[MVP], Jul 17, 2003
    #2
    1. Advertising

  3. Postback is accounted for on page_load

    What's driving me nuts is I've narrowed it down to the action is being
    handled, but nothing is coming out of the datagrid, see code:

    Private Sub dgPatients_SelectedIndexChanged(ByVal sender As
    System.Object, ByVal e As System.EventArgs) Handles
    dgPatients.SelectedIndexChanged

    Dim pID As String

    pID = dgPatients.SelectedItem.Cells(1).Text
    Response.Write(("PID=" & pID))
    ....

    pID (yes, there is a number in the cell in the datagrid) is coming out
    blank, even though I get a SelectedItem.ItemIndex in the handler.

    Datagrid is as follows:

    <asp:datagrid id="dgPatients" runat="server"
    AutoGenerateColumns="False">
    <AlternatingItemStyle
    BackColor="PaleGoldenrod"></AlternatingItemStyle>
    <ItemStyle BackColor="LightGoldenrodYellow"></ItemStyle>
    <HeaderStyle BackColor="Tan"></HeaderStyle>
    <Columns>
    <asp:ButtonColumn Text="Select" ButtonType="PushButton"
    CommandName="Select">
    <HeaderStyle Width="60px"></HeaderStyle>
    </asp:ButtonColumn>
    <asp:TemplateColumn HeaderText="Patient ID">
    <HeaderStyle HorizontalAlign="Center" Height="50px"
    Width="85px"></HeaderStyle>
    <ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
    <ItemTemplate>
    <asp:label runat="server" Width="85px" Text='<%#
    DataBinder.Eval(Container, "DataItem.patient_id") %>' >
    </asp:label>
    </ItemTemplate>
    </asp:TemplateColumn>
    ....
    </Columns>

    Keep in mind, another webform is set up identically, as near as I can
    tell, and and works.


    Thought for the day: "Do programmers swear more than persons of any
    other occupation?"


    "Sonali.NET[MVP]" <> wrote in message news:<#>...
    > Are you handling PostBack
    > "Richard Adams" <> wrote in message
    > news:...
    > > I've got two pages, each displaying a datagrid with a Select button
    > > column.
    > > With one the Select command is handled in the codebehind and works
    > > fine.
    > >
    > > The second page is a very similar setup, but designed after upgrading
    > > to Visual Studio 2003/Framework 1.1 Select evidently does something,
    > > but the event handling routine in codebehind doesn't execute. I've
    > > stripped away almost eveything on the form and even rebuilt the page
    > > from scratch and the Select button still is not handled.
    > >
    > > Checked document and form properties and all are identical to the
    > > first page, except meta tags (first page still refers to being created
    > > in VS.NET 7.0, rather than 7.1)
    > >
    > > Any ideas why the inconsistent behavior? How to see what the browser
    > > is attempting to send back to the server?
    > >
    > > I'm currently residing at No. 1 Witt's End.
    > >
    > > Richard
     
    Richard Adams, Jul 18, 2003
    #3
  4. Ok, this is really starting to annoy me...

    I just found my other page, the one that works, the column that works,
    is one I do on-ItemDataBound to format the one column I'm using as the
    key. I put an ItemDataBound into my non-working datagrid, for the
    patient_id column, and suddenly I get the SelectedItem.cells(n).text

    bound event handler:

    Private Sub dgPatients_ItemDataBound(ByVal sender As Object, ByVal e
    As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
    dgPatients.ItemDataBound
    Dim sTmp As String
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
    ListItemType.AlternatingItem Or e.Item.ItemType =
    ListItemType.SelectedItem Then
    sTmp = DataBinder.Eval(e.Item.DataItem, "patient_id")
    e.Item.Cells(1).Text = sTmp
    End If
    End Sub

    Without doing this I get nothing on dg.SelectedItem.cells(n).text on a
    select.

    I'm using asp:labels, tried
    Text='<%# DataBinder.Eval(Container, "DataItem.patient_name") %>'
    and
    Text='<%# Container.DataItem("patient_id") %>'
    but get nothing without the ItemDataBound for the desired column.
    What am I doing wrong?
     
    Richard Adams, Jul 18, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGFiYmxlcg==?=

    select gridview row without using select button?

    =?Utf-8?B?RGFiYmxlcg==?=, Mar 3, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    101,637
    dch31969
    Feb 27, 2009
  2. smcirish
    Replies:
    0
    Views:
    328
    smcirish
    Apr 22, 2008
  3. Matt
    Replies:
    2
    Views:
    233
    Roland Hall
    Jan 11, 2004
  4. palmiere
    Replies:
    1
    Views:
    474
    Erwin Moller
    Feb 9, 2004
  5. Gumtree
    Replies:
    3
    Views:
    281
    Matt Kruse
    Nov 10, 2004
Loading...

Share This Page