473,322 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Hide a button in a data grid

I have an item list for ordered products on a data grid in VS 2003.
It's an ASP page running VB behind it. All detail lines display as
well as all shipping charges. On the edit screen, we allow them to
cancel individual line items. We have the 'Cancel' button enabled for
the line items of the datagrid. However, I would like to hide that
button for the shipping charges. We don't want them cancelling their
shipping fees, after all.

Has anyone ever tried to hide a cancel/add/delete button in a data grid
for a specific row?

Thanks for your help.

Dec 7 '06 #1
3 2325
OHM
There are a few approaches you could use. But one way is to handle the
ItemDataBound event for the datagrid. You can then use the item which is
passed to the function to interrogate a value in the row and hide the button
control in the appropriate row.

HTH

--
OHM
http://TrainingOn.net
<ke*********@excite.comwrote in message
news:11**********************@80g2000cwy.googlegro ups.com...
>I have an item list for ordered products on a data grid in VS 2003.
It's an ASP page running VB behind it. All detail lines display as
well as all shipping charges. On the edit screen, we allow them to
cancel individual line items. We have the 'Cancel' button enabled for
the line items of the datagrid. However, I would like to hide that
button for the shipping charges. We don't want them cancelling their
shipping fees, after all.

Has anyone ever tried to hide a cancel/add/delete button in a data grid
for a specific row?

Thanks for your help.

Dec 7 '06 #2

Hi
Don't know about datagrid; but if you use a gridview you just set the text
property of the cell to null and the button vanishes and is thus disabled
(also the row is not contracted to the left)
Viz.
spreadsCell.Text = null;
(see the very end of this listing for usage within context)
horizButton is being turned off when it has no details to display
HTH
Mark Carew
-------------------------------------------------
using System;
using System.Data;
using System.Data.Common;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class issues : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session.Remove("articleno");
}
protected void umeArticlesRowCommand(Object src, GridViewCommandEventArgs
e)
{
string commandIs = e.CommandName;
if (commandIs == "HorizSpreads")
{
// get the row index stored in the CommandArgument property
int index = Convert.ToInt32(e.CommandArgument);
// get the GridViewRow where the command is raised
GridViewRow selectedRow = ((GridView)e.CommandSource).Rows[index];
// get the umeNo
string spreadUmeNo = selectedRow.Cells[0].Text;
// get the ArticleNo
string spreadArticleNo = selectedRow.Cells[1].Text;
// Show the spreads
Session["UmeNo"] = spreadUmeNo;
Session["ArticleNo"] = spreadArticleNo;
Server.Transfer("scrollSpreads.aspx");
}
}
protected void umeIssuesRowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView gva = (GridView)e.Row.FindControl("umeArticlesGridView") ;
string connectString =
ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

// get the description or the articles for this issue
string stringUmeNo =
((DataRowView)e.Row.DataItem)["umeno"].ToString();
string umeArticleSelectCommand =
"SELECT * FROM umeArticle WHERE umeno = " +
stringUmeNo;
SqlDataSource arts =
new SqlDataSource(connectString, umeArticleSelectCommand);
gva.DataSource = arts;
gva.AutoGenerateColumns = false;

//
BoundField bfUme = new BoundField();
bfUme.DataField = "umeNo";
gva.Columns.Add(bfUme);
gva.Columns[0].ItemStyle.Width = 25;

//
BoundField bfArticle = new BoundField();
bfArticle.DataField = "articleNo";
gva.Columns.Add(bfArticle);
gva.Columns[1].ItemStyle.Width = 25;

//
ButtonField horizButton = new ButtonField();
horizButton.ButtonType = ButtonType.Image;
horizButton.ImageUrl = "./Images/smallbluebutton.gif";
horizButton.CommandName = "HorizSpreads";
gva.Columns.Add(horizButton);
gva.Columns[2].ItemStyle.Width = 25;

//
BoundField bfDescription = new BoundField();
bfDescription.DataField = "description";
bfDescription.ItemStyle.Font.Name = "arial";
bfDescription.ItemStyle.Font.Size = 9;
bfDescription.ItemStyle.HorizontalAlign = HorizontalAlign.Left;
gva.Columns.Add(bfDescription);
gva.Columns[3].ItemStyle.Width = 550;

//
gva.RowDataBound += new
GridViewRowEventHandler(adjustSpreadRowVisibility) ;
//
gva.DataBind();
}
}
protected void adjustSpreadRowVisibility(object sender,
GridViewRowEventArgs e)
{
// for row that are data rows
if (e.Row.RowType == DataControlRowType.DataRow)
{
TableCell umeNo = e.Row.Cells[0];
umeNo.Visible = false;
TableCell articleNo = e.Row.Cells[1];
articleNo.Visible = false;
// get a reference to the spreads button cell
TableCell spreadsCell = e.Row.Cells[2];
// source the connection string from web.config
string connectString =
ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
// get the description or the articles for this issue
string stringUmeNo =
((DataRowView)e.Row.DataItem)["umeno"].ToString();
string stringArticleNo =
((DataRowView)e.Row.DataItem)["articleno"].ToString();
// create a factory to use for the count retrieval
DbProviderFactory factory;
string provider = "System.Data.SqlClient";
factory = DbProviderFactories.GetFactory(provider);
// open the connection
DbConnection conn = factory.CreateConnection();
conn.ConnectionString = connectString;
conn.Open();
// create the database command required to issue the count
DbCommand cmd = factory.CreateCommand();
cmd.CommandText =
"SELECT count(*) FROM umeSpread WHERE umeno = " +
stringUmeNo +
" AND articleNo = " +
stringArticleNo +
" AND spreadImage <''";
cmd.Connection = conn;
// execute the count query returning a single value
string spreadCountdr = cmd.ExecuteScalar().ToString();
conn.Close();
if (spreadCountdr == "0")
{
spreadsCell.Text = null;
// spreadsCell.Visible = false;
}
}
}
}

Dec 7 '06 #3
That worked like a charm. Thanks!

OHM wrote:
There are a few approaches you could use. But one way is to handle the
ItemDataBound event for the datagrid. You can then use the item which is
passed to the function to interrogate a value in the row and hide the button
control in the appropriate row.

HTH

--
OHM
http://TrainingOn.net
Dec 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Das | last post by:
Hi everyone, I'm using datagrid control to display the data. I want to hide column to be displayed into the data grid. I'm using the code as given below: Method given below is used to bind the...
0
by: Oz | last post by:
Hi Using VS.NET 2003, Windows XP SP1, We have a page which has been developed using ASP.NET. On it, is a button which when clicked is supposed to add some data to a table. When the button is...
3
by: vcornjamb | last post by:
Hello, I am developing a web form that contains some buttons and a data grid which has as its last column link buttons that will delete the data associated with that row. Everything works fine,...
1
by: Joe | last post by:
Hello All: I want to create a datagrid that looks like the following (here SHOW DETAILS and HIDE DETAILS would be link buttons which display detail information. Effectively they would toggle the...
0
by: Gian Paolo | last post by:
this is something really i can't find a reason. I have a form with a tabcontrol with tree pages, in the second page there is a Data GRid View. Plus i have a class. When i open the form i...
3
by: gilbert3b2g | last post by:
I'm new to Python, and programming in general. What I'm trying to do here is to load a list of accounts from a file on my harddrive into a string of Buttons in Tkinter, and when I press one of the...
5
by: crystalattice | last post by:
I'm creating a shelve interface using Tkinter. I have a button that allows the user to modify an existing entry; when the button is clicked, a new TopLevel window appears with Entry boxes holding...
4
by: =?Utf-8?B?U3JpZGhhcg==?= | last post by:
Hi, Is it possible to Hide/Show controls during a callback? I have a radio button list that does the callback. When it does the callback I need to refresh the grid to reflect the selected value...
0
by: zafar | last post by:
I don't know what property should be used for hiding colums in Data Grid, whereas in Data Grid View we have DataGridView1.Colums(index).Visible = False , But how can I hide Colums in Data Grid.....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.