GridView Cells

  • Thread starter Thread starter aljamala
  • Start date Start date
A

aljamala

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!
 
Hello (e-mail address removed),

http://groups.google.com/group/micr..._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?

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 Nietzsch
 
Hello (e-mail address removed),

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
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
 
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.
 
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
.....
 
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);

}
}
 
Hello (e-mail address removed),

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 Nietzsch
 

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

Similar Threads


Back
Top