DataGrid question

Discussion in 'ASP .Net' started by brock wade, Jun 5, 2008.

  1. brock wade

    brock wade Guest

    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:ButtonColumn Text="Details" CommandName="Details"
    ButtonType="PushButton"></asp:ButtonColumn>
    </asp:datagrid>

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

    Sub detailsClicked(ByVal sender As Object, ByVal e As
    DataGridCommandEventArgs)
    Response.Redirect("www.mysite.com\details.aspx")
    End Sub

    If so how can I pass the chosen record's key information into the new
    page to pickup the details?
    brock wade, Jun 5, 2008
    #1
    1. Advertising

  2. 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:ButtonColumn Text="Details" CommandName="Details"
    > ButtonType="PushButton"></asp:ButtonColumn>
    > </asp:datagrid>
    >
    > Should I go to my code-behind to do something like this?:
    >
    > Sub detailsClicked(ByVal sender As Object, ByVal e As
    > DataGridCommandEventArgs)
    > Response.Redirect("www.mysite.com\details.aspx")
    > End Sub
    >
    > If so how can I pass the chosen record's key information into the new
    > page to pickup the details?
    >
    Yankee Imperialist Dog, Jun 5, 2008
    #2
    1. Advertising

  3. On Jun 5, 1:37 pm, 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:ButtonColumn Text="Details" CommandName="Details"
    > ButtonType="PushButton"></asp:ButtonColumn>
    > </asp:datagrid>
    >
    > Should I go to my code-behind to do something like this?:
    >
    > Sub detailsClicked(ByVal sender As Object, ByVal e As
    > DataGridCommandEventArgs)
    > Response.Redirect("www.mysite.com\details.aspx")
    > 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 commandarguement to get the value.

    here's an example:

    protected void ItemDataBound(object sender, DataGridItemEventArgs e)
    {
    if (e.Item.ItemType== ListItemType.Item || e.Item.ItemType==
    ListItemType.AlternatingItem)
    {
    DataRowView drv = (DataRowView)e.Item.DataItem;
    ImageButton btn =
    (ImageButton)e.Item.FindControl("myImageButton");
    btn.CommandName = "MyCommandName";
    btn.CommandArguement = drv["ID"].ToString();
    }
    }

    then the itemcommand will look like this:

    protected void ItemCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    switch(e.CommandName)
    {
    default:
    break;
    case "MyCommandName":
    Response.Redirect("www.mysite.com\" +
    e.CommandArguement)
    break;
    }
    }
    the warlock society, Jun 5, 2008
    #3
  4. brock wade

    brock wade Guest

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

    On Jun 5, 2:09 pm, the warlock society <> wrote:
    > On Jun 5, 1:37 pm, 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:ButtonColumn Text="Details" CommandName="Details"
    > > ButtonType="PushButton"></asp:ButtonColumn>
    > >         </asp:datagrid>

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

    >
    > >     Sub detailsClicked(ByVal sender As Object, ByVal e As
    > > DataGridCommandEventArgs)
    > >         Response.Redirect("www.mysite.com\details.aspx")
    > >     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 commandarguement to get the value.
    >
    > here's an example:
    >
    > protected void ItemDataBound(object sender, DataGridItemEventArgs e)
    > {
    >      if (e.Item.ItemType== ListItemType.Item || e.Item.ItemType==
    > ListItemType.AlternatingItem)
    >      {
    >          DataRowView drv = (DataRowView)e.Item.DataItem;
    >          ImageButton btn =
    > (ImageButton)e.Item.FindControl("myImageButton");
    >          btn.CommandName = "MyCommandName";
    >          btn.CommandArguement = drv["ID"].ToString();
    >      }
    >
    > }
    >
    > then the itemcommand will look like this:
    >
    > protected void ItemCommand(object source,
    > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > {
    >      switch(e.CommandName)
    >      {
    >          default:
    >               break;
    >          case "MyCommandName":
    >               Response.Redirect("www.mysite.com\" +
    > e.CommandArguement)
    >               break;
    >      }
    >
    >
    >
    > }- Hide quoted text -
    >
    > - Show quoted text -- Hide quoted text -
    >
    > - Show quoted text -
    brock wade, Jun 5, 2008
    #4
  5. On Jun 5, 2:20 pm, brock wade <> wrote:
    > Forgot to mention, I'm using VB.net.
    >
    > On Jun 5, 2:09 pm, the warlock society <> wrote:
    >
    >
    >
    > > On Jun 5, 1:37 pm, 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:ButtonColumn Text="Details" CommandName="Details"
    > > > ButtonType="PushButton"></asp:ButtonColumn>
    > > >         </asp:datagrid>

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

    >
    > > >     Sub detailsClicked(ByVal sender As Object, ByVal e As
    > > > DataGridCommandEventArgs)
    > > >         Response.Redirect("www.mysite.com\details.aspx")
    > > >     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 commandarguement to get the value.

    >
    > > here's an example:

    >
    > > protected void ItemDataBound(object sender, DataGridItemEventArgs e)
    > > {
    > >      if (e.Item.ItemType== ListItemType.Item || e.Item.ItemType==
    > > ListItemType.AlternatingItem)
    > >      {
    > >          DataRowView drv = (DataRowView)e.Item.DataItem;
    > >          ImageButton btn =
    > > (ImageButton)e.Item.FindControl("myImageButton");
    > >          btn.CommandName = "MyCommandName";
    > >          btn.CommandArguement = drv["ID"].ToString();
    > >      }

    >
    > > }

    >
    > > then the itemcommand will look like this:

    >
    > > protected void ItemCommand(object source,
    > > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > > {
    > >      switch(e.CommandName)
    > >      {
    > >          default:
    > >               break;
    > >          case "MyCommandName":
    > >               Response.Redirect("www.mysite.com\" +
    > > e.CommandArguement)
    > >               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.
    the warlock society, Jun 5, 2008
    #5
  6. 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 <> 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:ButtonColumn Text="Details" CommandName="Details"
    > > ButtonType="PushButton"></asp:ButtonColumn>
    > > </asp:datagrid>
    > >
    > > Should I go to my code-behind to do something like this?:
    > >
    > > Sub detailsClicked(ByVal sender As Object, ByVal e As
    > > DataGridCommandEventArgs)
    > > Response.Redirect("www.mysite.com\details.aspx")
    > > 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 commandarguement to get the value.
    >
    > here's an example:
    >
    > protected void ItemDataBound(object sender, DataGridItemEventArgs e)
    > {
    > if (e.Item.ItemType== ListItemType.Item || e.Item.ItemType==
    > ListItemType.AlternatingItem)
    > {
    > DataRowView drv = (DataRowView)e.Item.DataItem;
    > ImageButton btn =
    > (ImageButton)e.Item.FindControl("myImageButton");
    > btn.CommandName = "MyCommandName";
    > btn.CommandArguement = drv["ID"].ToString();
    > }
    > }
    >
    > then the itemcommand will look like this:
    >
    > protected void ItemCommand(object source,
    > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > {
    > switch(e.CommandName)
    > {
    > default:
    > break;
    > case "MyCommandName":
    > Response.Redirect("www.mysite.com\" +
    > e.CommandArguement)
    > break;
    > }
    > }
    >
    Yankee Imperialist Dog, Jun 5, 2008
    #6
  7. brock wade

    brock wade Guest

    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.CommandArgument"
    even though Intellisense lists it as a choice "Option Strict On
    disallows implicit conversions from 'System.Object' to Boolean'. I'm
    assuming the "Response.Redirect("c:\inetpub\wwwroot\HR_ReportingTool
    \HR_ReportingToolClient_1\Details.aspx"" +", e.CommandArgument)" is
    basically correct for the redirect since my application itself resides
    at "c:\inetpub\wwwroot\HR_ReportingTool\HR_ReportingToolClient_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.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    lblWelcome.Text = "Hello " & Global.UserSecurity.Fname.Trim &
    " " & Global.UserSecurity.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).GetActionCurrent(Global.UserSecurity.EmpId, Today,
    Global.UserName, Global.UserPassword, Global.appDataSource)
    pos = (New PositionBroker).GetPosition(act.PositionID,
    Global.UserName, Global.UserPassword, Global.appDataSource)
    m_department = pos.Department.Name
    Dim emps As Employees = (New
    EmployeeBroker).GetCurrentEmployeesByDepartment(m_department,
    Global.UserName, Global.UserPassword, Global.appDataSource)
    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.DataSource = dt
    dgEmployees.DataBind()

    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).GetActionCurrent(dr.Key, Today, Global.UserName,
    Global.UserPassword, Global.appDataSource)
    Dim employee As DataRow = dt.NewRow
    employee("Emp #") = dr.Key
    employee("Last Name") = dr.LastName
    employee("First Name") = dr.FirstName
    employee("Title") = EmpPos.WorkAgainstInfo.Title
    dt.Rows.Add(employee)
    End Sub 'SetListViewItem

    Protected Sub ItemDataBound(ByVal sender As Object, ByVal e As
    DataGridItemEventArgs)
    If ((e.Item.ItemType = ListItemType.Item) _
    OrElse (e.Item.ItemType =
    ListItemType.AlternatingItem)) Then
    Dim drv As DataRowView = CType(e.Item.DataItem,
    DataRowView)
    Dim btn As ImageButton =
    CType(e.Item.FindControl("Details"), ImageButton)
    btn.CommandName = "Details"
    btn.CommandArgument = drv("Key").ToString
    End If
    End Sub

    Protected Sub OnItemCommand(ByVal source As Object, ByVal e As
    System.Web.UI.WebControls.DataGridCommandEventArgs)
    Select Case (e.CommandName)
    Case "Details"
    Response.Redirect("c:\inetpub\wwwroot\HR_ReportingTool
    \HR_ReportingToolClient_1\Details.aspx"" +", e.CommandArgument)
    End Select
    End Sub
    ' ****** END PARTIAL SAMPLE OF
    THE CODE-BEHIND ******

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

    <asp:datagrid id="dgEmployees" runat="server" lowSorting="True"
    <Columns>
    <asp:ButtonColumn Text="Details" CommandName="Details"
    ButtonType="PushButton"></asp:ButtonColumn>
    </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 <> wrote:
    > On Jun 5, 2:20 pm, brock wade <> wrote:
    >
    >
    >
    >
    >
    > > Forgot to mention, I'm using VB.net.

    >
    > > On Jun 5, 2:09 pm, the warlock society <> wrote:

    >
    > > > On Jun 5, 1:37 pm, 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:ButtonColumn Text="Details" CommandName="Details"
    > > > > ButtonType="PushButton"></asp:ButtonColumn>
    > > > >         </asp:datagrid>

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

    >
    > > > >     Sub detailsClicked(ByVal sender As Object, ByVal e As
    > > > > DataGridCommandEventArgs)
    > > > >         Response.Redirect("www.mysite.com\details.aspx")
    > > > >     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 commandarguement to get the value.

    >
    > > > here's an example:

    >
    > > > protected void ItemDataBound(object sender, DataGridItemEventArgs e)
    > > > {
    > > >      if (e.Item.ItemType== ListItemType.Item || e.Item.ItemType==
    > > > ListItemType.AlternatingItem)
    > > >      {
    > > >          DataRowView drv = (DataRowView)e.Item.DataItem;
    > > >          ImageButton btn =
    > > > (ImageButton)e.Item.FindControl("myImageButton");
    > > >          btn.CommandName = "MyCommandName";
    > > >          btn.CommandArguement = drv["ID"].ToString();
    > > >      }

    >
    > > > }

    >
    > > > then the itemcommand will look like this:

    >
    > > > protected void ItemCommand(object source,
    > > > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > > > {
    > > >      switch(e.CommandName)
    > > >      {
    > > >          default:
    > > >               break;
    > > >          case "MyCommandName":
    > > >               Response.Redirect("www.mysite.com\" +
    > > > e.CommandArguement)
    > > >               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 -
    brock wade, Jun 6, 2008
    #7
  8. brock wade

    brock wade Guest

    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.CommandArgument"
    even though Intellisense lists it as a choice "Option Strict On
    disallows implicit conversions from 'System.Object' to Boolean'. I'm
    assuming the "Response.Redirect("c:\inetpub\wwwroot\HR_ReportingTool
    \HR_ReportingToolClient_1\Details.aspx"" +", e.CommandArgument)" is
    basically correct for the redirect since my application itself
    resides
    at "c:\inetpub\wwwroot\HR_ReportingTool\HR_ReportingToolClient_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.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    lblWelcome.Text = "Hello " & Global.UserSecurity.Fname.Trim &
    " " & Global.UserSecurity.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).GetActionCurrent(Global.UserSecurity.EmpId, Today,
    Global.UserName, Global.UserPassword, Global.appDataSource)
    pos = (New PositionBroker).GetPosition(act.PositionID,
    Global.UserName, Global.UserPassword, Global.appDataSource)
    m_department = pos.Department.Name
    Dim emps As Employees = (New
    EmployeeBroker).GetCurrentEmployeesByDepartment(m_department,
    Global.UserName, Global.UserPassword, Global.appDataSource)
    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.DataSource = dt
    dgEmployees.DataBind()


    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).GetActionCurrent(dr.Key, Today, Global.UserName,
    Global.UserPassword, Global.appDataSource)
    Dim employee As DataRow = dt.NewRow
    employee("Emp #") = dr.Key
    employee("Last Name") = dr.LastName
    employee("First Name") = dr.FirstName
    employee("Title") = EmpPos.WorkAgainstInfo.Title
    dt.Rows.Add(employee)
    End Sub 'SetListViewItem


    Protected Sub ItemDataBound(ByVal sender As Object, ByVal e As
    DataGridItemEventArgs)
    If ((e.Item.ItemType = ListItemType.Item) _
    OrElse (e.Item.ItemType =
    ListItemType.AlternatingItem)) Then
    Dim drv As DataRowView = CType(e.Item.DataItem,
    DataRowView)
    Dim btn As ImageButton =
    CType(e.Item.FindControl("Details"), ImageButton)
    btn.CommandName = "Details"
    btn.CommandArgument = drv("Key").ToString
    End If
    End Sub


    Protected Sub OnItemCommand(ByVal source As Object, ByVal e As
    System.Web.UI.WebControls.DataGridCommandEventArgs)
    Select Case (e.CommandName)
    Case "Details"
    Response.Redirect("c:\inetpub\wwwroot
    \HR_ReportingTool
    \HR_ReportingToolClient_1\Details.aspx"" +", e.CommandArgument)
    End Select
    End Sub
    ' ****** END PARTIAL SAMPLE OF
    THE CODE-BEHIND ******


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


    <asp:datagrid id="dgEmployees" runat="server" lowSorting="True"
    <Columns>
    <asp:ButtonColumn Text="Details"
    CommandName="Details"
    ButtonType="PushButton"></asp:ButtonColumn>
    </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 <> wrote:
    > On Jun 5, 2:20 pm, brock wade <> wrote:
    >
    >
    >
    >
    >
    > > Forgot to mention, I'm using VB.net.

    >
    > > On Jun 5, 2:09 pm, the warlock society <> wrote:

    >
    > > > On Jun 5, 1:37 pm, 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:ButtonColumn Text="Details" CommandName="Details"
    > > > > ButtonType="PushButton"></asp:ButtonColumn>
    > > > >         </asp:datagrid>

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

    >
    > > > >     Sub detailsClicked(ByVal sender As Object, ByVal e As
    > > > > DataGridCommandEventArgs)
    > > > >         Response.Redirect("www.mysite.com\details.aspx")
    > > > >     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 commandarguement to get the value.

    >
    > > > here's an example:

    >
    > > > protected void ItemDataBound(object sender, DataGridItemEventArgs e)
    > > > {
    > > >      if (e.Item.ItemType== ListItemType.Item || e.Item.ItemType==
    > > > ListItemType.AlternatingItem)
    > > >      {
    > > >          DataRowView drv = (DataRowView)e.Item.DataItem;
    > > >          ImageButton btn =
    > > > (ImageButton)e.Item.FindControl("myImageButton");
    > > >          btn.CommandName = "MyCommandName";
    > > >          btn.CommandArguement = drv["ID"].ToString();
    > > >      }

    >
    > > > }

    >
    > > > then the itemcommand will look like this:

    >
    > > > protected void ItemCommand(object source,
    > > > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > > > {
    > > >      switch(e.CommandName)
    > > >      {
    > > >          default:
    > > >               break;
    > > >          case "MyCommandName":
    > > >               Response.Redirect("www.mysite.com\" +
    > > > e.CommandArguement)
    > > >               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 -
    brock wade, Jun 9, 2008
    #8
  9. brock wade

    brock wade Guest

    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
    <> wrote:
    > 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 <> 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:ButtonColumn Text="Details" CommandName="Details"
    > > > ButtonType="PushButton"></asp:ButtonColumn>
    > > >         </asp:datagrid>

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

    >
    > > >     Sub detailsClicked(ByVal sender As Object, ByVal e As
    > > > DataGridCommandEventArgs)
    > > >         Response.Redirect("www.mysite.com\details.aspx")
    > > >     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 commandarguement to get the value.

    >
    > > here's an example:

    >
    > > protected void ItemDataBound(object sender, DataGridItemEventArgs e)
    > > {
    > >      if (e.Item.ItemType== ListItemType.Item || e.Item.ItemType==
    > > ListItemType.AlternatingItem)
    > >      {
    > >          DataRowView drv = (DataRowView)e.Item.DataItem;
    > >          ImageButton btn =
    > > (ImageButton)e.Item.FindControl("myImageButton");
    > >          btn.CommandName = "MyCommandName";
    > >          btn.CommandArguement = drv["ID"].ToString();
    > >      }
    > > }

    >
    > > then the itemcommand will look like this:

    >
    > > protected void ItemCommand(object source,
    > > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > > {
    > >      switch(e.CommandName)
    > >      {
    > >          default:
    > >               break;
    > >          case "MyCommandName":
    > >               Response.Redirect("www.mysite.com\" +
    > > e.CommandArguement)
    > >               break;
    > >      }
    > > }- Hide quoted text -

    >
    > - Show quoted text -
    brock wade, Jun 10, 2008
    #9
    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. Dave
    Replies:
    0
    Views:
    431
  2. BK Kim

    datagrid in datagrid

    BK Kim, Feb 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    527
    Alvin Bruney [MVP]
    Mar 2, 2004
  3. =?Utf-8?B?U3VyZXNo?=
    Replies:
    0
    Views:
    512
    =?Utf-8?B?U3VyZXNo?=
    Mar 2, 2004
  4. Brian K. Williams
    Replies:
    0
    Views:
    534
    Brian K. Williams
    Mar 2, 2004
  5. Andreas Klemt
    Replies:
    0
    Views:
    266
    Andreas Klemt
    Oct 8, 2003
Loading...

Share This Page