Is it possible to acheive the following using a DataGrid in ASP.NE

Discussion in 'ASP .Net Datagrid Control' started by Ben (Melb, Vic, Aus), Sep 7, 2005.

  1. I'm hoping that someone might be able to help me with the following challenge.

    The problems lies in the ability to display rows and columns of data on a
    datagrid conditionally.

    I have a list of rows in a data grid with one of the columns being a date. I
    have a hyperlink column for every row which allows me to remove a row from
    the grid. I would like to disable the ability to remove a row if the date is
    in the past, is this possible using a DataGrid?

    Thanks in advance for your assistance.
    Ben
     
    Ben (Melb, Vic, Aus), Sep 7, 2005
    #1
    1. Advertising

  2. Yes, it is possible, but you must create a Template field with a Hyperlink control in it.
    Then on the DataBid Event or (RowDataBound) of the grid, use this code.
    In this code I check if a date exists and set the value of two different Hyperlinks...

    The declaritive code looks like this (All ASP.NET 1.1) (In grid column)
    <ItemTemplate>
    <asp:HyperLink id="lnkEdit" runat="server" NavigateUrl="../Eval_EventEdit.aspx?Eval_EventGUID={0}">Edit Details
    </ItemTemplate>
    // get the datarow view of the item

    DataRowView drv = (DataRowView)e.Item.DataItem;

    if (drv == null) return;



    // get the Answer Radio button that is being created

    System.Web.UI.Control ctlEdit = e.Item.FindControl("lnkEdit");
    if (ctlEdit != null)
    {

    HyperLink lnkEdit = (HyperLink)ctlEdit;

    switch (drv["Eval_Date"].ToString().Length)

    {

    case 0:

    // does an event exists

    if (drv["Eval_EventGUID"].ToString().Length == 0)

    {

    // event does not exists

    lnkEdit.Text = "Start First Evaluation";

    lnkEdit.NavigateUrl = string.Format("../Eval_EventCreate.aspx?DealerID={0}", drv["DealerID"]);

    }

    else

    {

    lnkEdit.Text = "Complete results";

    lnkEdit.NavigateUrl = string.Format(lnkEdit.NavigateUrl, drv["Eval_EventGUID"]);

    }

    break;

    default:

    lnkEdit.Text = "Edit/Print results/comments";

    lnkEdit.NavigateUrl = string.Format(lnkEdit.NavigateUrl, drv["Eval_EventGUID"]);

    break;

    }

    }

    "Ben (Melb, Vic, Aus)" <> wrote in message news:...
    > I'm hoping that someone might be able to help me with the following challenge.
    >
    > The problems lies in the ability to display rows and columns of data on a
    > datagrid conditionally.
    >
    > I have a list of rows in a data grid with one of the columns being a date. I
    > have a hyperlink column for every row which allows me to remove a row from
    > the grid. I would like to disable the ability to remove a row if the date is
    > in the past, is this possible using a DataGrid?
    >
    > Thanks in advance for your assistance.
    > Ben
    >
     
    Gerhard Pretorius, Sep 7, 2005
    #2
    1. Advertising

  3. Thanks for Gerhard's informative suggestion.

    Hi Ben,

    As Gerhard has mentioned, we can use a template column instead of the
    Buildin button column, and put a asp.net submit button in the template
    column(set the proper commandName, such as "Edit", "Delete"...). Thus, we
    can freely access the control in template column (through the DataGrid's
    ItemDataBound" event) and modify the nested button's property according to
    the binding data. Gerhard has provided some detailed code snippet, if you
    still have any further question, please feel free to post here. Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    --------------------
    | From: "Gerhard Pretorius" <>
    | References: <>
    | Subject: Re: Is it possible to acheive the following using a DataGrid in
    ASP.NE
    | Date: Wed, 7 Sep 2005 09:11:53 +0200
    | Lines: 222
    | MIME-Version: 1.0
    | Content-Type: multipart/alternative;
    | boundary="----=_NextPart_000_0118_01C5B38C.305C35F0"
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
    | Message-ID: <>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | NNTP-Posting-Host: 196.15.187.131
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridcontrol:5477
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    |
    | Yes, it is possible, but you must create a Template field with a
    Hyperlink control in it.
    | Then on the DataBid Event or (RowDataBound) of the grid, use this code.
    | In this code I check if a date exists and set the value of two different
    Hyperlinks...
    | The declaritive code looks like this (All ASP.NET 1.1) (In grid column)
    | <ItemTemplate>
    | <asp:HyperLink id="lnkEdit" runat="server"
    NavigateUrl="../Eval_EventEdit.aspx?Eval_EventGUID={0}">Edit Details
    </ItemTemplate>
    | // get the datarow view of the item
    | DataRowView drv = (DataRowView)e.Item.DataItem;
    | if (drv == null) return;
    | // get the Answer Radio button that is being created
    | System.Web.UI.Control ctlEdit = e.Item.FindControl("lnkEdit");
    | if (ctlEdit != null)
    | {
    | HyperLink lnkEdit = (HyperLink)ctlEdit;
    | switch (drv["Eval_Date"].ToString().Length)
    | {
    | case 0:
    | // does an event exists
    | if (drv["Eval_EventGUID"].ToString().Length == 0)
    | {
    | // event does not exists
    | lnkEdit.Text = "Start First Evaluation";
    | lnkEdit.NavigateUrl =
    string.Format("../Eval_EventCreate.aspx?DealerID={0}", drv["DealerID"]);
    | }
    | else
    | {
    | lnkEdit.Text = "Complete results";
    | lnkEdit.NavigateUrl = string.Format(lnkEdit.NavigateUrl,
    drv["Eval_EventGUID"]);
    | }
    | break;
    | default:
    | lnkEdit.Text = "Edit/Print results/comments";
    | lnkEdit.NavigateUrl = string.Format(lnkEdit.NavigateUrl,
    drv["Eval_EventGUID"]);
    | break;
    | }
    | }
    | "Ben (Melb, Vic, Aus)" <> wrote in message
    news:...
    | > I'm hoping that someone might be able to help me with the following
    challenge.
    | >
    | > The problems lies in the ability to display rows and columns of data on
    a
    | > datagrid conditionally.
    | >
    | > I have a list of rows in a data grid with one of the columns being a
    date. I
    | > have a hyperlink column for every row which allows me to remove a row
    from
    | > the grid. I would like to disable the ability to remove a row if the
    date is
    | > in the past, is this possible using a DataGrid?
    | >
    | > Thanks in advance for your assistance.
    | > Ben
    | >
    |
     
    Steven Cheng[MSFT], Sep 7, 2005
    #3
  4. Hi Ben,

    Any progress on this issue? If there're any further question or anything
    else we can help, please feel free to post here. Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    --------------------
    | X-Tomcat-ID: 205362784
    | References: <>
    <>
    | MIME-Version: 1.0
    | Content-Type: text/plain
    | Content-Transfer-Encoding: 7bit
    | From: (Steven Cheng[MSFT])
    | Organization: Microsoft
    | Date: Wed, 07 Sep 2005 08:51:16 GMT
    | Subject: Re: Is it possible to acheive the following using a DataGrid in
    ASP.NE
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | Message-ID: <>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | Lines: 98
    | Path: TK2MSFTNGXA01.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridcontrol:5478
    | NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
    |
    | Thanks for Gerhard's informative suggestion.
    |
    | Hi Ben,
    |
    | As Gerhard has mentioned, we can use a template column instead of the
    | Buildin button column, and put a asp.net submit button in the template
    | column(set the proper commandName, such as "Edit", "Delete"...). Thus, we
    | can freely access the control in template column (through the DataGrid's
    | ItemDataBound" event) and modify the nested button's property according
    to
    | the binding data. Gerhard has provided some detailed code snippet, if you
    | still have any further question, please feel free to post here. Thanks,
    |
    | Steven Cheng
    | Microsoft Online Support
    |
    | Get Secure! www.microsoft.com/security
    | (This posting is provided "AS IS", with no warranties, and confers no
    | rights.)
    | --------------------
    | | From: "Gerhard Pretorius" <>
    | | References: <>
    | | Subject: Re: Is it possible to acheive the following using a DataGrid
    in
    | ASP.NE
    | | Date: Wed, 7 Sep 2005 09:11:53 +0200
    | | Lines: 222
    | | MIME-Version: 1.0
    | | Content-Type: multipart/alternative;
    | | boundary="----=_NextPart_000_0118_01C5B38C.305C35F0"
    | | X-Priority: 3
    | | X-MSMail-Priority: Normal
    | | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
    | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
    | | Message-ID: <>
    | | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | | NNTP-Posting-Host: 196.15.187.131
    | | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
    | | Xref: TK2MSFTNGXA01.phx.gbl
    | microsoft.public.dotnet.framework.aspnet.datagridcontrol:5477
    | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | |
    | | Yes, it is possible, but you must create a Template field with a
    | Hyperlink control in it.
    | | Then on the DataBid Event or (RowDataBound) of the grid, use this code.
    | | In this code I check if a date exists and set the value of two
    different
    | Hyperlinks...
    | | The declaritive code looks like this (All ASP.NET 1.1) (In grid column)
    | | <ItemTemplate>
    | | <asp:HyperLink id="lnkEdit" runat="server"
    | NavigateUrl="../Eval_EventEdit.aspx?Eval_EventGUID={0}">Edit Details
    | </ItemTemplate>
    | | // get the datarow view of the item
    | | DataRowView drv = (DataRowView)e.Item.DataItem;
    | | if (drv == null) return;
    | | // get the Answer Radio button that is being created
    | | System.Web.UI.Control ctlEdit = e.Item.FindControl("lnkEdit");
    | | if (ctlEdit != null)
    | | {
    | | HyperLink lnkEdit = (HyperLink)ctlEdit;
    | | switch (drv["Eval_Date"].ToString().Length)
    | | {
    | | case 0:
    | | // does an event exists
    | | if (drv["Eval_EventGUID"].ToString().Length == 0)
    | | {
    | | // event does not exists
    | | lnkEdit.Text = "Start First Evaluation";
    | | lnkEdit.NavigateUrl =
    | string.Format("../Eval_EventCreate.aspx?DealerID={0}", drv["DealerID"]);
    | | }
    | | else
    | | {
    | | lnkEdit.Text = "Complete results";
    | | lnkEdit.NavigateUrl = string.Format(lnkEdit.NavigateUrl,
    | drv["Eval_EventGUID"]);
    | | }
    | | break;
    | | default:
    | | lnkEdit.Text = "Edit/Print results/comments";
    | | lnkEdit.NavigateUrl = string.Format(lnkEdit.NavigateUrl,
    | drv["Eval_EventGUID"]);
    | | break;
    | | }
    | | }
    | | "Ben (Melb, Vic, Aus)" <> wrote in message
    | news:...
    | | > I'm hoping that someone might be able to help me with the following
    | challenge.
    | | >
    | | > The problems lies in the ability to display rows and columns of data
    on
    | a
    | | > datagrid conditionally.
    | | >
    | | > I have a list of rows in a data grid with one of the columns being a
    | date. I
    | | > have a hyperlink column for every row which allows me to remove a row
    | from
    | | > the grid. I would like to disable the ability to remove a row if the
    | date is
    | | > in the past, is this possible using a DataGrid?
    | | >
    | | > Thanks in advance for your assistance.
    | | > Ben
    | | >
    | |
    |
    |
     
    Steven Cheng[MSFT], Sep 12, 2005
    #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. Simon Harvey

    Is the following possible?

    Simon Harvey, Feb 23, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    284
    Eric Lawrence [MSFT]
    Feb 23, 2004
  2. Markis Landis Gardner
    Replies:
    1
    Views:
    280
    Rudi Angela
    Feb 26, 2004
  3. Andreas Klemt
    Replies:
    0
    Views:
    319
    Andreas Klemt
    Oct 8, 2003
  4. Jack
    Replies:
    2
    Views:
    146
    Ray Costanzo [MVP]
    Feb 26, 2005
  5. How to acheive this ..

    , May 5, 2006, in forum: Javascript
    Replies:
    5
    Views:
    125
    Sriram
    May 5, 2006
Loading...

Share This Page