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

  • Thread starter Ben (Melb, Vic, Aus)
  • Start date
B

Ben (Melb, Vic, Aus)

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
 
G

Gerhard Pretorius

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;

}

}
 
S

Steven Cheng[MSFT]

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" <[email protected]>
| References: <[email protected]>
| 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: <[email protected]>
| 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;
| }
| }
| > 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
| >
|
 
S

Steven Cheng[MSFT]

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: <[email protected]>
<[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: (e-mail address removed) (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: <[email protected]>
| 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" <[email protected]>
| | References: <[email protected]>
| | 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: <[email protected]>
| | 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;
| | }
| | }
| | | > 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
| | >
| |
|
|
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top