DataGrid question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • brock wade

    DataGrid question

    I have a Datagrid that is working fine displying my records, but I'm
    trying to program buttons
    on each record line to launch another web page that shows all the
    details for the product:

    <asp:datagrid id="dgProducts " runat="server">
    <asp:ButtonColu mn Text="Details" CommandName="De tails"
    ButtonType="Pus hButton"></asp:ButtonColum n>
    </asp:datagrid>

    Should I go to my code-behind to do something like this?:

    Sub detailsClicked( ByVal sender As Object, ByVal e As
    DataGridCommand EventArgs)
    Response.Redire ct("www.mysite. com\details.asp x")
    End Sub

    If so how can I pass the chosen record's key information into the new
    page to pickup the details?
  • =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?=

    #2
    RE: DataGrid question

    You can do it that way and bind the key you need to display details to the
    EventArgument.
    you can just add a hyperlink to the datagrind and bind the key to the url
    similar to
    above.
    Or if you want to get creative you can set the post back url on the button
    to your detail page. just be careful of circular references. (i can give you
    an artical if you want to know how to do that)
    --
    Share The Knowledge. I need all the help I can get and so do you!


    "brock wade" wrote:
    I have a Datagrid that is working fine displying my records, but I'm
    trying to program buttons
    on each record line to launch another web page that shows all the
    details for the product:
    >
    <asp:datagrid id="dgProducts " runat="server">
    <asp:ButtonColu mn Text="Details" CommandName="De tails"
    ButtonType="Pus hButton"></asp:ButtonColum n>
    </asp:datagrid>
    >
    Should I go to my code-behind to do something like this?:
    >
    Sub detailsClicked( ByVal sender As Object, ByVal e As
    DataGridCommand EventArgs)
    Response.Redire ct("www.mysite. com\details.asp x")
    End Sub
    >
    If so how can I pass the chosen record's key information into the new
    page to pickup the details?
    >

    Comment

    • the warlock society

      #3
      Re: DataGrid question

      On Jun 5, 1:37 pm, brock wade <brockusw...@ya hoo.comwrote:
      I have a Datagrid that is working fine displying my records, but I'm
      trying to program buttons
      on each record line to launch another web page that shows all the
      details for the product:
      >
      <asp:datagrid id="dgProducts " runat="server">
      <asp:ButtonColu mn Text="Details" CommandName="De tails"
      ButtonType="Pus hButton"></asp:ButtonColum n>
      </asp:datagrid>
      >
      Should I go to my code-behind to do something like this?:
      >
      Sub detailsClicked( ByVal sender As Object, ByVal e As
      DataGridCommand EventArgs)
      Response.Redire ct("www.mysite. com\details.asp x")
      End Sub
      >
      If so how can I pass the chosen record's key information into the new
      page to pickup the details?
      Brock

      In the Itemdatabound event you'll want to set the button's
      commandargument to the chosen record's key.
      Also set the button's commandname to something like "redirect" or
      something that associates that commandname with the event you're
      firing.

      You're going to capture the button's click event in the OnItemCommand
      event of the datagrid. Make a simple select case statement that
      checks the command name's property of the button - inside that
      statement you'll check the commandarguemen t to get the value.

      here's an example:

      protected void ItemDataBound(o bject sender, DataGridItemEve ntArgs e)
      {
      if (e.Item.ItemTyp e== ListItemType.It em || e.Item.ItemType ==
      ListItemType.Al ternatingItem)
      {
      DataRowView drv = (DataRowView)e. Item.DataItem;
      ImageButton btn =
      (ImageButton)e. Item.FindContro l("myImageButto n");
      btn.CommandName = "MyCommandName" ;
      btn.CommandArgu ement = drv["ID"].ToString();
      }
      }

      then the itemcommand will look like this:

      protected void ItemCommand(obj ect source,
      System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
      {
      switch(e.Comman dName)
      {
      default:
      break;
      case "MyCommandName" :
      Response.Redire ct("www.mysite. com\" +
      e.CommandArguem ent)
      break;
      }
      }

      Comment

      • brock wade

        #4
        Re: DataGrid question

        Forgot to mention, I'm using VB.net.

        On Jun 5, 2:09 pm, the warlock society <sh...@tlfst.co mwrote:
        On Jun 5, 1:37 pm, brock wade <brockusw...@ya hoo.comwrote:
        >
        >
        >
        >
        >
        I have a Datagrid that is working fine displying my records, but I'm
        trying to program buttons
        on each record line to launch another web page that shows all the
        details for the product:
        >
        <asp:datagrid id="dgProducts " runat="server">
                <asp:ButtonColu mn Text="Details" CommandName="De tails"
        ButtonType="Pus hButton"></asp:ButtonColum n>
                </asp:datagrid>
        >
        Should I go to my code-behind to do something like this?:
        >
            Sub detailsClicked( ByVal sender As Object, ByVal e As
        DataGridCommand EventArgs)
                Response.Redire ct("www.mysite. com\details.asp x")
            End Sub
        >
        If so how can I pass the chosen record's key information into the new
        page to pickup the details?
        >
        Brock
        >
        In the Itemdatabound event you'll want to set the button's
        commandargument to the chosen record's key.
        Also set the button's commandname to something like "redirect" or
        something that associates that commandname with the event you're
        firing.
        >
        You're going to capture the button's click event in the OnItemCommand
        event of the datagrid.  Make a simple select case statement that
        checks the command name's property of the button - inside that
        statement you'll check the commandarguemen t to get the value.
        >
        here's an example:
        >
        protected void ItemDataBound(o bject sender, DataGridItemEve ntArgs e)
        {
             if (e.Item.ItemTyp e== ListItemType.It em || e.Item.ItemType ==
        ListItemType.Al ternatingItem)
             {
                 DataRowView drv = (DataRowView)e. Item.DataItem;
                 ImageButton btn =
        (ImageButton)e. Item.FindContro l("myImageButto n");
                 btn.CommandName = "MyCommandName" ;
                 btn.CommandArgu ement = drv["ID"].ToString();
             }
        >
        }
        >
        then the itemcommand will look like this:
        >
        protected void ItemCommand(obj ect source,
        System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
        {
             switch(e.Comman dName)
             {
                 default:
                      break;
                 case "MyCommandName" :
                      Response.Redire ct("www.mysite. com\" +
        e.CommandArguem ent)
                      break;
             }
        >
        >
        >
        }- Hide quoted text -
        >
        - Show quoted text -- Hide quoted text -
        >
        - Show quoted text -

        Comment

        • the warlock society

          #5
          Re: DataGrid question

          On Jun 5, 2:20 pm, brock wade <brockusw...@ya hoo.comwrote:
          Forgot to mention, I'm using VB.net.
          >
          On Jun 5, 2:09 pm, the warlock society <sh...@tlfst.co mwrote:
          >
          >
          >
          On Jun 5, 1:37 pm, brock wade <brockusw...@ya hoo.comwrote:
          >
          I have a Datagrid that is working fine displying my records, but I'm
          trying to program buttons
          on each record line to launch another web page that shows all the
          details for the product:
          >
          <asp:datagrid id="dgProducts " runat="server">
                  <asp:ButtonColu mn Text="Details" CommandName="De tails"
          ButtonType="Pus hButton"></asp:ButtonColum n>
                  </asp:datagrid>
          >
          Should I go to my code-behind to do something like this?:
          >
              Sub detailsClicked( ByVal sender As Object, ByVal e As
          DataGridCommand EventArgs)
                  Response.Redire ct("www.mysite. com\details.asp x")
              End Sub
          >
          If so how can I pass the chosen record's key information into the new
          page to pickup the details?
          >
          Brock
          >
          In the Itemdatabound event you'll want to set the button's
          commandargument to the chosen record's key.
          Also set the button's commandname to something like "redirect" or
          something that associates that commandname with the event you're
          firing.
          >
          You're going to capture the button's click event in the OnItemCommand
          event of the datagrid.  Make a simple select case statement that
          checks the command name's property of the button - inside that
          statement you'll check the commandarguemen t to get the value.
          >
          here's an example:
          >
          protected void ItemDataBound(o bject sender, DataGridItemEve ntArgs e)
          {
               if (e.Item.ItemTyp e== ListItemType.It em || e.Item.ItemType ==
          ListItemType.Al ternatingItem)
               {
                   DataRowView drv = (DataRowView)e. Item.DataItem;
                   ImageButton btn =
          (ImageButton)e. Item.FindContro l("myImageButto n");
                   btn.CommandName = "MyCommandName" ;
                   btn.CommandArgu ement = drv["ID"].ToString();
               }
          >
          }
          >
          then the itemcommand will look like this:
          >
          protected void ItemCommand(obj ect source,
          System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
          {
               switch(e.Comman dName)
               {
                   default:
                        break;
                   case "MyCommandName" :
                        Response.Redire ct("www.mysite. com\" +
          e.CommandArguem ent)
                        break;
               }
          >
          }- Hide quoted text -
          >
          - Show quoted text -- Hide quoted text -
          >
          - Show quoted text -- Hide quoted text -
          >
          - Show quoted text -
          heh well I could translate it to vb.net for you but honestly there
          isnt much difference. The concepts are exactly the same - the
          difference is merely syntactical.

          If you're having a problem deciphering c# you can just copy and paste
          it into a c#/vb.net translator - there's a handful of them on the web.

          Comment

          • =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?=

            #6
            Re: DataGrid question

            if it's a simple key you should be able to bind it directly without going to
            the event.
            Use the designer and bind the key by selecting the button and selection the
            data item you want.
            --
            Share The Knowledge. I need all the help I can get and so do you!


            "the warlock society" wrote:
            On Jun 5, 1:37 pm, brock wade <brockusw...@ya hoo.comwrote:
            I have a Datagrid that is working fine displying my records, but I'm
            trying to program buttons
            on each record line to launch another web page that shows all the
            details for the product:

            <asp:datagrid id="dgProducts " runat="server">
            <asp:ButtonColu mn Text="Details" CommandName="De tails"
            ButtonType="Pus hButton"></asp:ButtonColum n>
            </asp:datagrid>

            Should I go to my code-behind to do something like this?:

            Sub detailsClicked( ByVal sender As Object, ByVal e As
            DataGridCommand EventArgs)
            Response.Redire ct("www.mysite. com\details.asp x")
            End Sub

            If so how can I pass the chosen record's key information into the new
            page to pickup the details?
            >
            Brock
            >
            In the Itemdatabound event you'll want to set the button's
            commandargument to the chosen record's key.
            Also set the button's commandname to something like "redirect" or
            something that associates that commandname with the event you're
            firing.
            >
            You're going to capture the button's click event in the OnItemCommand
            event of the datagrid. Make a simple select case statement that
            checks the command name's property of the button - inside that
            statement you'll check the commandarguemen t to get the value.
            >
            here's an example:
            >
            protected void ItemDataBound(o bject sender, DataGridItemEve ntArgs e)
            {
            if (e.Item.ItemTyp e== ListItemType.It em || e.Item.ItemType ==
            ListItemType.Al ternatingItem)
            {
            DataRowView drv = (DataRowView)e. Item.DataItem;
            ImageButton btn =
            (ImageButton)e. Item.FindContro l("myImageButto n");
            btn.CommandName = "MyCommandName" ;
            btn.CommandArgu ement = drv["ID"].ToString();
            }
            }
            >
            then the itemcommand will look like this:
            >
            protected void ItemCommand(obj ect source,
            System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
            {
            switch(e.Comman dName)
            {
            default:
            break;
            case "MyCommandName" :
            Response.Redire ct("www.mysite. com\" +
            e.CommandArguem ent)
            break;
            }
            }
            >

            Comment

            • brock wade

              #7
              Re: DataGrid question

              Thanks for the translator tip - I'm a newbi in ASP.net so I've got a
              lot to learn. I got the basic translation to place into my code-
              behind. I do have a few questions to make sure I'm following the logic
              here. For one thing the compiler does not like the "e.CommandArgum ent"
              even though Intellisense lists it as a choice "Option Strict On
              disallows implicit conversions from 'System.Object' to Boolean'. I'm
              assuming the "Response.Redir ect("c:\inetpub \wwwroot\HR_Rep ortingTool
              \HR_ReportingTo olClient_1\Deta ils.aspx"" +", e.CommandArgume nt)" is
              basically correct for the redirect since my application itself resides
              at "c:\inetpub\www root\HR_Reporti ngTool\HR_Repor tingToolClient_ 1".
              Plus I hope I'm referencing the Button name correctly between the code-
              behind and the html as "Details":

              ' ****** PARTIAL SAMPLE OF THE
              CODE-BEHIND ******
              Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
              System.EventArg s) Handles MyBase.Load
              'Put user code to initialize the page here
              lblWelcome.Text = "Hello " & Global.UserSecu rity.Fname.Trim &
              " " & Global.UserSecu rity.Lname
              Dim act As Action
              Dim pos As Position
              Dim empname As String
              Dim lvi As ListItem
              Dim Employee As Employee
              Dim empcount As Integer
              act = (New
              ActionBroker).G etActionCurrent (Global.UserSec urity.EmpId, Today,
              Global.UserName , Global.UserPass word, Global.appDataS ource)
              pos = (New PositionBroker) .GetPosition(ac t.PositionID,
              Global.UserName , Global.UserPass word, Global.appDataS ource)
              m_department = pos.Department. Name
              Dim emps As Employees = (New
              EmployeeBroker) .GetCurrentEmpl oyeesByDepartme nt(m_department ,
              Global.UserName , Global.UserPass word, Global.appDataS ource)
              Dim dt As New DataTable
              Dim count As Integer = 0
              For Each emp As Employee In emps
              SetListViewItem (emp, dt, count)
              count = count + 1
              Next
              dgEmployees.Dat aSource = dt
              dgEmployees.Dat aBind()

              End Sub

              Private Sub SetListViewItem (ByVal dr As Employee, ByVal dt As
              DataTable, ByVal count As Integer)
              If count = 0 Then
              dt.Columns.Add( "Emp #")
              dt.Columns.Add( "Last Name")
              dt.Columns.Add( "First Name")
              dt.Columns.Add( "Title")
              End If
              Dim EmpPos As Action = (New
              ActionBroker).G etActionCurrent (dr.Key, Today, Global.UserName ,
              Global.UserPass word, Global.appDataS ource)
              Dim employee As DataRow = dt.NewRow
              employee("Emp #") = dr.Key
              employee("Last Name") = dr.LastName
              employee("First Name") = dr.FirstName
              employee("Title ") = EmpPos.WorkAgai nstInfo.Title
              dt.Rows.Add(emp loyee)
              End Sub 'SetListViewIte m

              Protected Sub ItemDataBound(B yVal sender As Object, ByVal e As
              DataGridItemEve ntArgs)
              If ((e.Item.ItemTy pe = ListItemType.It em) _
              OrElse (e.Item.ItemTyp e =
              ListItemType.Al ternatingItem)) Then
              Dim drv As DataRowView = CType(e.Item.Da taItem,
              DataRowView)
              Dim btn As ImageButton =
              CType(e.Item.Fi ndControl("Deta ils"), ImageButton)
              btn.CommandName = "Details"
              btn.CommandArgu ment = drv("Key").ToSt ring
              End If
              End Sub

              Protected Sub OnItemCommand(B yVal source As Object, ByVal e As
              System.Web.UI.W ebControls.Data GridCommandEven tArgs)
              Select Case (e.CommandName)
              Case "Details"
              Response.Redire ct("c:\inetpub\ wwwroot\HR_Repo rtingTool
              \HR_ReportingTo olClient_1\Deta ils.aspx"" +", e.CommandArgume nt)
              End Select
              End Sub
              ' ****** END PARTIAL SAMPLE OF
              THE CODE-BEHIND ******

              ' ****** HTML ******

              <asp:datagrid id="dgEmployees " runat="server" lowSorting="Tru e"
              <Columns>
              <asp:ButtonColu mn Text="Details" CommandName="De tails"
              ButtonType="Pus hButton"></asp:ButtonColum n>
              </Columns>
              </asp:datagrid>

              Of course I am a ways away from creating the Employees Detail .aspx
              and about 20 text boxes hopefully to be filled with the balance of the
              Employee fields.

              Thanks!!!! Brockus








              On Jun 5, 2:27 pm, the warlock society <sh...@tlfst.co mwrote:
              On Jun 5, 2:20 pm, brock wade <brockusw...@ya hoo.comwrote:
              >
              >
              >
              >
              >
              Forgot to mention, I'm using VB.net.
              >
              On Jun 5, 2:09 pm, the warlock society <sh...@tlfst.co mwrote:
              >
              On Jun 5, 1:37 pm, brock wade <brockusw...@ya hoo.comwrote:
              >
              I have a Datagrid that is working fine displying my records, but I'm
              trying to program buttons
              on each record line to launch another web page that shows all the
              details for the product:
              >
              <asp:datagrid id="dgProducts " runat="server">
                      <asp:ButtonColu mn Text="Details" CommandName="De tails"
              ButtonType="Pus hButton"></asp:ButtonColum n>
                      </asp:datagrid>
              >
              Should I go to my code-behind to do something like this?:
              >
                  Sub detailsClicked( ByVal sender As Object, ByVal e As
              DataGridCommand EventArgs)
                      Response.Redire ct("www.mysite. com\details.asp x")
                  End Sub
              >
              If so how can I pass the chosen record's key information into the new
              page to pickup the details?
              >
              Brock
              >
              In the Itemdatabound event you'll want to set the button's
              commandargument to the chosen record's key.
              Also set the button's commandname to something like "redirect" or
              something that associates that commandname with the event you're
              firing.
              >
              You're going to capture the button's click event in the OnItemCommand
              event of the datagrid.  Make a simple select case statement that
              checks the command name's property of the button - inside that
              statement you'll check the commandarguemen t to get the value.
              >
              here's an example:
              >
              protected void ItemDataBound(o bject sender, DataGridItemEve ntArgs e)
              {
                   if (e.Item.ItemTyp e== ListItemType.It em || e.Item.ItemType ==
              ListItemType.Al ternatingItem)
                   {
                       DataRowView drv = (DataRowView)e. Item.DataItem;
                       ImageButton btn =
              (ImageButton)e. Item.FindContro l("myImageButto n");
                       btn.CommandName = "MyCommandName" ;
                       btn.CommandArgu ement = drv["ID"].ToString();
                   }
              >
              }
              >
              then the itemcommand will look like this:
              >
              protected void ItemCommand(obj ect source,
              System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
              {
                   switch(e.Comman dName)
                   {
                       default:
                            break;
                       case "MyCommandName" :
                            Response.Redire ct("www.mysite. com\" +
              e.CommandArguem ent)
                            break;
                   }
              >
              }- Hide quoted text -
              >
              - Show quoted text -- Hide quoted text -
              >
              - Show quoted text -- Hide quoted text -
              >
              - Show quoted text -
              >
              heh well I could translate it to vb.net for you but honestly there
              isnt much difference.  The concepts are exactly the same - the
              difference is merely syntactical.
              >
              If you're having a problem deciphering c# you can just copy and paste
              it into a c#/vb.net translator - there's a handful of them on the web.- Hide quoted text -
              >
              - Show quoted text -

              Comment

              • brock wade

                #8
                Re: DataGrid question

                Thanks for the translator tip - I'm a newbi in ASP.net so I've got a
                lot to learn. I got the basic translation to place into my code-
                behind. I do have a few questions to make sure I'm following the
                logic
                here. For one thing the compiler does not like the
                "e.CommandArgum ent"
                even though Intellisense lists it as a choice "Option Strict On
                disallows implicit conversions from 'System.Object' to Boolean'. I'm
                assuming the "Response.Redir ect("c:\inetpub \wwwroot\HR_Rep ortingTool
                \HR_ReportingTo olClient_1\Deta ils.aspx"" +", e.CommandArgume nt)" is
                basically correct for the redirect since my application itself
                resides
                at "c:\inetpub\www root\HR_Reporti ngTool\HR_Repor tingToolClient_ 1".
                Plus I hope I'm referencing the Button name correctly between the
                code-
                behind and the html as "Details":

                ' ****** PARTIAL SAMPLE OF THE
                CODE-BEHIND ******
                Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
                System.EventArg s) Handles MyBase.Load
                'Put user code to initialize the page here
                lblWelcome.Text = "Hello " & Global.UserSecu rity.Fname.Trim &
                " " & Global.UserSecu rity.Lname
                Dim act As Action
                Dim pos As Position
                Dim empname As String
                Dim lvi As ListItem
                Dim Employee As Employee
                Dim empcount As Integer
                act = (New
                ActionBroker).G etActionCurrent (Global.UserSec urity.EmpId, Today,
                Global.UserName , Global.UserPass word, Global.appDataS ource)
                pos = (New PositionBroker) .GetPosition(ac t.PositionID,
                Global.UserName , Global.UserPass word, Global.appDataS ource)
                m_department = pos.Department. Name
                Dim emps As Employees = (New
                EmployeeBroker) .GetCurrentEmpl oyeesByDepartme nt(m_department ,
                Global.UserName , Global.UserPass word, Global.appDataS ource)
                Dim dt As New DataTable
                Dim count As Integer = 0
                For Each emp As Employee In emps
                SetListViewItem (emp, dt, count)
                count = count + 1
                Next
                dgEmployees.Dat aSource = dt
                dgEmployees.Dat aBind()


                End Sub


                Private Sub SetListViewItem (ByVal dr As Employee, ByVal dt As
                DataTable, ByVal count As Integer)
                If count = 0 Then
                dt.Columns.Add( "Emp #")
                dt.Columns.Add( "Last Name")
                dt.Columns.Add( "First Name")
                dt.Columns.Add( "Title")
                End If
                Dim EmpPos As Action = (New
                ActionBroker).G etActionCurrent (dr.Key, Today, Global.UserName ,
                Global.UserPass word, Global.appDataS ource)
                Dim employee As DataRow = dt.NewRow
                employee("Emp #") = dr.Key
                employee("Last Name") = dr.LastName
                employee("First Name") = dr.FirstName
                employee("Title ") = EmpPos.WorkAgai nstInfo.Title
                dt.Rows.Add(emp loyee)
                End Sub 'SetListViewIte m


                Protected Sub ItemDataBound(B yVal sender As Object, ByVal e As
                DataGridItemEve ntArgs)
                If ((e.Item.ItemTy pe = ListItemType.It em) _
                OrElse (e.Item.ItemTyp e =
                ListItemType.Al ternatingItem)) Then
                Dim drv As DataRowView = CType(e.Item.Da taItem,
                DataRowView)
                Dim btn As ImageButton =
                CType(e.Item.Fi ndControl("Deta ils"), ImageButton)
                btn.CommandName = "Details"
                btn.CommandArgu ment = drv("Key").ToSt ring
                End If
                End Sub


                Protected Sub OnItemCommand(B yVal source As Object, ByVal e As
                System.Web.UI.W ebControls.Data GridCommandEven tArgs)
                Select Case (e.CommandName)
                Case "Details"
                Response.Redire ct("c:\inetpub\ wwwroot
                \HR_ReportingTo ol
                \HR_ReportingTo olClient_1\Deta ils.aspx"" +", e.CommandArgume nt)
                End Select
                End Sub
                ' ****** END PARTIAL SAMPLE OF
                THE CODE-BEHIND ******


                ' ****** HTML ******


                <asp:datagrid id="dgEmployees " runat="server" lowSorting="Tru e"
                <Columns>
                <asp:ButtonColu mn Text="Details"
                CommandName="De tails"
                ButtonType="Pus hButton"></asp:ButtonColum n>
                </Columns>
                </asp:datagrid>


                Of course I am a ways away from creating the Employees Detail .aspx
                and about 20 text boxes hopefully to be filled with the balance of
                the
                Employee fields.


                Thanks!!!! Brockus




                On Jun 5, 2:27 pm, the warlock society <sh...@tlfst.co mwrote:
                On Jun 5, 2:20 pm, brock wade <brockusw...@ya hoo.comwrote:
                >
                >
                >
                >
                >
                Forgot to mention, I'm using VB.net.
                >
                On Jun 5, 2:09 pm, the warlock society <sh...@tlfst.co mwrote:
                >
                On Jun 5, 1:37 pm, brock wade <brockusw...@ya hoo.comwrote:
                >
                I have a Datagrid that is working fine displying my records, but I'm
                trying to program buttons
                on each record line to launch another web page that shows all the
                details for the product:
                >
                <asp:datagrid id="dgProducts " runat="server">
                        <asp:ButtonColu mn Text="Details" CommandName="De tails"
                ButtonType="Pus hButton"></asp:ButtonColum n>
                        </asp:datagrid>
                >
                Should I go to my code-behind to do something like this?:
                >
                    Sub detailsClicked( ByVal sender As Object, ByVal e As
                DataGridCommand EventArgs)
                        Response.Redire ct("www.mysite. com\details.asp x")
                    End Sub
                >
                If so how can I pass the chosen record's key information into the new
                page to pickup the details?
                >
                Brock
                >
                In the Itemdatabound event you'll want to set the button's
                commandargument to the chosen record's key.
                Also set the button's commandname to something like "redirect" or
                something that associates that commandname with the event you're
                firing.
                >
                You're going to capture the button's click event in the OnItemCommand
                event of the datagrid.  Make a simple select case statement that
                checks the command name's property of the button - inside that
                statement you'll check the commandarguemen t to get the value.
                >
                here's an example:
                >
                protected void ItemDataBound(o bject sender, DataGridItemEve ntArgs e)
                {
                     if (e.Item.ItemTyp e== ListItemType.It em || e.Item.ItemType ==
                ListItemType.Al ternatingItem)
                     {
                         DataRowView drv = (DataRowView)e. Item.DataItem;
                         ImageButton btn =
                (ImageButton)e. Item.FindContro l("myImageButto n");
                         btn.CommandName = "MyCommandName" ;
                         btn.CommandArgu ement = drv["ID"].ToString();
                     }
                >
                }
                >
                then the itemcommand will look like this:
                >
                protected void ItemCommand(obj ect source,
                System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
                {
                     switch(e.Comman dName)
                     {
                         default:
                              break;
                         case "MyCommandName" :
                              Response.Redire ct("www.mysite. com\" +
                e.CommandArguem ent)
                              break;
                     }
                >
                }- Hide quoted text -
                >
                - Show quoted text -- Hide quoted text -
                >
                - Show quoted text -- Hide quoted text -
                >
                - Show quoted text -
                >
                heh well I could translate it to vb.net for you but honestly there
                isnt much difference.  The concepts are exactly the same - the
                difference is merely syntactical.
                >
                If you're having a problem deciphering c# you can just copy and paste
                it into a c#/vb.net translator - there's a handful of them on the web.- Hide quoted text -
                >
                - Show quoted text -

                Comment

                • brock wade

                  #9
                  Re: DataGrid question

                  Sould I be binding the actual DataGrid to the DataSource using "Simple
                  Binding" which gives me the Option of "Page"? If so or not how do I
                  launch then my Details.aspx and pickup the fileds on that screen which
                  correspond to the reocord chosen by the button specific to the
                  datarow?
                  Thanks!


                  On Jun 5, 2:29 pm, Yankee Imperialist Dog
                  <YankeeImperial ist...@discussi ons.microsoft.c omwrote:
                  if it's a simple key you should be able to bind it directly without going to
                  the event.
                  Use the designer and bind the key by selecting the button and selection the
                  data item you want.
                  --
                  Share The Knowledge. I need all the help I can get and so do you!
                  >
                  >
                  >
                  "the warlock society" wrote:
                  On Jun 5, 1:37 pm, brock wade <brockusw...@ya hoo.comwrote:
                  I have a Datagrid that is working fine displying my records, but I'm
                  trying to program buttons
                  on each record line to launch another web page that shows all the
                  details for the product:
                  >
                  <asp:datagrid id="dgProducts " runat="server">
                          <asp:ButtonColu mn Text="Details" CommandName="De tails"
                  ButtonType="Pus hButton"></asp:ButtonColum n>
                          </asp:datagrid>
                  >
                  Should I go to my code-behind to do something like this?:
                  >
                      Sub detailsClicked( ByVal sender As Object, ByVal e As
                  DataGridCommand EventArgs)
                          Response.Redire ct("www.mysite. com\details.asp x")
                      End Sub
                  >
                  If so how can I pass the chosen record's key information into the new
                  page to pickup the details?
                  >
                  Brock
                  >
                  In the Itemdatabound event you'll want to set the button's
                  commandargument to the chosen record's key.
                  Also set the button's commandname to something like "redirect" or
                  something that associates that commandname with the event you're
                  firing.
                  >
                  You're going to capture the button's click event in the OnItemCommand
                  event of the datagrid.  Make a simple select case statement that
                  checks the command name's property of the button - inside that
                  statement you'll check the commandarguemen t to get the value.
                  >
                  here's an example:
                  >
                  protected void ItemDataBound(o bject sender, DataGridItemEve ntArgs e)
                  {
                       if (e.Item.ItemTyp e== ListItemType.It em || e.Item.ItemType ==
                  ListItemType.Al ternatingItem)
                       {
                           DataRowView drv = (DataRowView)e. Item.DataItem;
                           ImageButton btn =
                  (ImageButton)e. Item.FindContro l("myImageButto n");
                           btn.CommandName = "MyCommandName" ;
                           btn.CommandArgu ement = drv["ID"].ToString();
                       }
                  }
                  >
                  then the itemcommand will look like this:
                  >
                  protected void ItemCommand(obj ect source,
                  System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
                  {
                       switch(e.Comman dName)
                       {
                           default:
                                break;
                           case "MyCommandName" :
                                Response.Redire ct("www.mysite. com\" +
                  e.CommandArguem ent)
                                break;
                       }
                  }- Hide quoted text -
                  >
                  - Show quoted text -

                  Comment

                  Working...