473,398 Members | 2,427 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,398 software developers and data experts.

GridView Cells

Hi,

I was wondering if there is a way to make a single cell readonly within
a GridView? I know you can do it for a column but what about a cell
within that column?

Thanks!

Nov 28 '06 #1
7 10356
Hello al******@gmail.com,

http://groups.google.com/group/micro...b4aa3a2b7a7318
I was wondering if there is a way to make a single cell readonly
within a GridView? I know you can do it for a column but what about a
cell within that column?

Thanks!
---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Nov 28 '06 #2
>
http://groups.google.com/group/micro...b4aa3a2b7a7318
I was wondering if there is a way to make a single cell readonly
within a GridView? I know you can do it for a column but what about a
cell within that column?
Thats for a DataGrid (Windows not Web controls)

Nov 28 '06 #3
Hello al******@gmail.com,

Sorry, missed topic a little bit (too tired after work)

Have u tried to handle CellBeginEdit and check the index of your cell in
GridViewCellCancelEventArgs to call Cancel property as described there
http://msdn2.microsoft.com/en-us/library/ms993231.aspx
>http://groups.google.com/group/micro...framework.wind
owsforms.controls/browse_frm/thread/a28d453ee51dea45/fdb4aa3a2b7a7318
>>I was wondering if there is a way to make a single cell readonly
within a GridView? I know you can do it for a column but what about
a cell within that column?
Thats for a DataGrid (Windows not Web controls)
---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Nov 28 '06 #4
Thats alright Michael, I know the feeling.

However, the article you are referring to is again for windows forms, I
believe this is for the new DataGridView class.

>
Sorry, missed topic a little bit (too tired after work)

Have u tried to handle CellBeginEdit and check the index of your cell in
GridViewCellCancelEventArgs to call Cancel property as described there
http://msdn2.microsoft.com/en-us/library/ms993231.aspx
http://groups.google.com/group/micro...framework.wind
owsforms.controls/browse_frm/thread/a28d453ee51dea45/fdb4aa3a2b7a7318

I was wondering if there is a way to make a single cell readonly
within a GridView? I know you can do it for a column but what about
a cell within that column?
Thats for a DataGrid (Windows not Web controls)
Nov 28 '06 #5
This is what I'm trying to do, the property value DOES change, but I
feel like this isnt the correct way of doing it. There may be
something else needed missing?

Here is my RowCommand event code it will basically kick into edit mode
when a user double clicks on a row:

protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
GridView _gridView = (GridView)sender;

// Get the selected index and the command name
int _selectedIndex = int.Parse(e.CommandArgument.ToString());
string _commandName = e.CommandName;
string _eventArgument = Request.Form["__EVENTARGUMENT"];

DataControlFieldCell cell =
((DataControlFieldCell)gameGrid.Rows[1].Controls[3]);
BoundField field1 = (BoundField)(cell.ContainingField);
//field1.ItemStyle.Width.Value = "100";
TextBox1.Text = TextBox1.Text + cell.Text;
lblStatus.Text = lblStatus.Text + field1.ReadOnly.ToString();
if (cell.Text == @" ")
{
field1.ReadOnly = false;
//cell.DataBind();

}
else
{
field1.ReadOnly = true;
//cell.DataBind();
}
lblStatus.Text = lblStatus.Text + field1.ReadOnly.ToString();
BindGrid();
switch (_commandName)
{
case ("SingleClick"):
_gridView.SelectedIndex = _selectedIndex;
this.Message.Text += "Single clicked GridView row at
index " + _selectedIndex.ToString() + " on cell index " +
_eventArgument + "<br />";
break;
case ("DoubleClick"):
_gridView.EditIndex = _selectedIndex;
_gridView.SelectedIndex = -1;
BindGrid();
this.Message.Text += "Double clicked GridView row at
index " + _selectedIndex.ToString() + " on cell index " +
_eventArgument + "<br />";
break;
}
}

I tried following the ReadOnly propoerty values across post backs
initial: False
my change: True
postback: False
my change: True
postback: False
mychage: True
.....

Nov 28 '06 #6
Problem fixed...in the RowDataBound event, I check if its in edit mode,
if so, then I check to see if the cell has a value and set the ReadOnly
property based on that.

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
DataControlFieldCell cell;
TemplateField field;

if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Edit
|| e.Row.RowState == (DataControlRowState.Edit
| DataControlRowState.Alternate))
{
GridViewRow row = e.Row;
for (int index = 1; index < 10; index++)
{
TextBox4.Text = TextBox4.Text + "\r\n" +
String.Concat("SudokuCell", index).ToString();
TextBox theCell =
(TextBox)row.FindControl(String.Concat("SudokuCell ", index));
// lblStatus2.Text = lblStatus2.Text + (theCell.Text
== @"").ToString();
if (theCell.Text == @"")
{
theCell.ReadOnly = false;
//theCell.Enabled = false;
//TextBox1.Text = theCell.ToString();
}
else
{

theCell.ReadOnly = true;
//theCell.Enabled = false;
theCell.BorderStyle = BorderStyle.None;
theCell.BorderWidth =
System.Web.UI.WebControls.Unit.Pixel(0);

}
}

Nov 29 '06 #7
Hello al******@gmail.com,

Good. Bookmarked.
Tnx
Problem fixed...in the RowDataBound event, I check if its in edit
mode, if so, then I check to see if the cell has a value and set the
ReadOnly property based on that.

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
DataControlFieldCell cell;
TemplateField field;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Edit
|| e.Row.RowState == (DataControlRowState.Edit
| DataControlRowState.Alternate))
{
GridViewRow row = e.Row;
for (int index = 1; index < 10; index++)
{
TextBox4.Text = TextBox4.Text + "\r\n" +
String.Concat("SudokuCell", index).ToString();
TextBox theCell =
(TextBox)row.FindControl(String.Concat("SudokuCell ", index));
// lblStatus2.Text = lblStatus2.Text +
(theCell.Text
== @"").ToString();
if (theCell.Text == @"")
{
theCell.ReadOnly = false;
//theCell.Enabled = false;
//TextBox1.Text = theCell.ToString();
}
else
{
theCell.ReadOnly = true;
//theCell.Enabled = false;
theCell.BorderStyle = BorderStyle.None;
theCell.BorderWidth =
System.Web.UI.WebControls.Unit.Pixel(0);
}
}
---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Nov 29 '06 #8

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

Similar topics

1
by: tfsmag | last post by:
Hello, I have a function that returns a dynamically created gridview. This works fine, however it does not seem to be able to maintain state when adding sorting or paging to the gridview. Does...
10
by: NH | last post by:
I have a girdview with paging enabled. How can I add a message in the footer to say "Viewing records 1-15 of 45" etc Thanks
1
by: Mike P | last post by:
When you use a SqlDataSource to hook up data to a GridView it seems to be to be very inflexible. For example, I want to create my own Delete button with my own code and I also want to create a...
0
by: den 2005 | last post by:
Hi everybody, I created a Gridview with a TemplateField and there is Label control in ItemTemplate and a DropdownList control in EditItemTemplate, I was to displayed them ok when I click the...
1
by: Evan M. | last post by:
Here's my GridView and my SqlDataSource <asp:GridView ID="ContactHistoryGrid" runat="server" AutoGenerateColumns="False" DataSourceID="ContactHistoryDS" DataKeyNames="JobHistoryID"...
0
by: pargat.singh | last post by:
Hi Everyone: I have a gridview control with AllowSorting="True" and work ok. But my page will be used by different user from different region so i need to change the HeaderText based on language...
0
by: pargat.singh | last post by:
Hi: I am using a grid and having a problem with sorting. Below are my code and change the header name at run time as below based on language.If i don't change the header name it work. Can...
4
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have a gridview. I am using template columns inside the gridview. When I display the gridview on the web page and if there is no value in a particular cell, gridline disappaers...
5
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I have a sub in vb.net that adds extra headers to a gridview and it works very well. however, i tried to translate it to c# and i'm getting the header inserting itself over the first datarows and...
1
by: mghihor | last post by:
Dear GridView Experts! I have problems with GridView when adding a column using TemplateField. I fill GridView1 from a stored procedure. It has a Select statement and returns 14 columns,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.