EditItemTemplate question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I only display the textbox I have in an EditItemTemplate based on the
value in another cell in the row?

i.e I only want users to edit one of the cells based on the value in another
cell....

Should I do this in the ItemDataBound event of the datagrid...something
like...
If e.Item.Cells(8).Text = "2" Then
dont allow the textbox defined in the EditItemTemplate to be visible
what is the code for this?
End If

Thanks for your help
 
thanks for the reply.

I get a "Object reference not set to an instance of an object" error with
the line
CType(e.Item.FindControl("txtDaysWriteOffed"), TextBox).Visible = False

Should the EditItemTemplate control be referenceable in the ItemDataBound
datagrid event? Its as if it doesnt know about the control?
 
the line its failing on is
CType(e.Item.Controls("txtDaysWriteOffed"), TextBox).Enabled = False

Its says "Input string was not in a correct format. "
 
i think it should be

CType(e.Item.Controls.FindControl("txtDaysWriteOffed"), TextBox).Enabled =
False

Adding the 'FindControl' in there
 
Yes I tried that but it says "FindControl" is not a member of
System.Web.UI.ControlCollection"

thanks
 
Yeah this is something I tried also, get an ""Object reference not set to an
instance of an object" error.

It looks like the EditItemTemplate control is not referenceabnle in the
ItemDataBound event?
 
How about if you try that code in the EditCommand

private void DataGrid1_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

e.Item.FindControl("");

}



not sure the VB code for that, but accessed through the DataGrid property
'EditCommand'
 
No, tired that too, but got the same Object reference not set to an instance
of an object" error.

Is there a way of doing this? It should be simply!!
 
tried that too, go the same object not set...error

This should be a simple thing to do, any other ideas? I am tried everything
I know...
 
GOT IT

After much fighting with Visual Studio - which kept removing my DataGrid
events, i found a way
In your EditCommand method, hide the Column you don't want to show,

So, if the TextBox will appear in Column 4, in you EditCommand Method do as
follows:

private void DataGrid1_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

DatGrid1.EditItemIndex = e.Item.ItemIndex;

BindTopicGrid(this.m_user);

if(e.Item.Cells(8).Text = "2" then

DataGrid1.Columns[4].Visible = false;

End If

}

Again, HTH
 
Hi Grant,
I really appreciate all your effort on this. I really need to keep the
column visible, its just the txtbox in the EditItemTemplate. Anyway of doin
it?

Grant Merwitz said:
GOT IT

After much fighting with Visual Studio - which kept removing my DataGrid
events, i found a way
In your EditCommand method, hide the Column you don't want to show,

So, if the TextBox will appear in Column 4, in you EditCommand Method do as
follows:

private void DataGrid1_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

DatGrid1.EditItemIndex = e.Item.ItemIndex;

BindTopicGrid(this.m_user);

if(e.Item.Cells(8).Text = "2" then

DataGrid1.Columns[4].Visible = false;

End If

}

Again, HTH

NH said:
tried that too, go the same object not set...error

This should be a simple thing to do, any other ideas? I am tried
everything
I know...
 
Sorry man, all out of ideas and time .. home time

Try start a new post, as not many people will look at this one again - its
massive :)

Good luck

NH said:
Hi Grant,
I really appreciate all your effort on this. I really need to keep the
column visible, its just the txtbox in the EditItemTemplate. Anyway of
doin
it?

Grant Merwitz said:
GOT IT

After much fighting with Visual Studio - which kept removing my DataGrid
events, i found a way
In your EditCommand method, hide the Column you don't want to show,

So, if the TextBox will appear in Column 4, in you EditCommand Method do
as
follows:

private void DataGrid1_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

DatGrid1.EditItemIndex = e.Item.ItemIndex;

BindTopicGrid(this.m_user);

if(e.Item.Cells(8).Text = "2" then

DataGrid1.Columns[4].Visible = false;

End If

}

Again, HTH

NH said:
tried that too, go the same object not set...error

This should be a simple thing to do, any other ideas? I am tried
everything
I know...

:

How about if you try that code in the EditCommand

private void DataGrid1_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

e.Item.FindControl("");

}



not sure the VB code for that, but accessed through the DataGrid
property
'EditCommand'


Yeah this is something I tried also, get an ""Object reference not
set
to
an
instance of an object" error.

It looks like the EditItemTemplate control is not referenceabnle in
the
ItemDataBound event?

:

sorry, drop out the control bit

e.Item.FindControl("MyControl")


Yes I tried that but it says "FindControl" is not a member of
System.Web.UI.ControlCollection"

thanks

:

i think it should be

CType(e.Item.Controls.FindControl("txtDaysWriteOffed"),
TextBox).Enabled
=
False

Adding the 'FindControl' in there

the line its failing on is
CType(e.Item.Controls("txtDaysWriteOffed"), TextBox).Enabled =
False

Its says "Input string was not in a correct format. "

:

thanks for the reply.

I get a "Object reference not set to an instance of an
object"
error
with
the line
CType(e.Item.FindControl("txtDaysWriteOffed"),
TextBox).Visible
=
False

Should the EditItemTemplate control be referenceable in the
ItemDataBound
datagrid event? Its as if it doesnt know about the control?

:

e.Item.Controls.FindControl("TextBox's Id").Visible =
false;



How can I only display the textbox I have in an
EditItemTemplate
based on
the
value in another cell in the row?

i.e I only want users to edit one of the cells based on
the
value
in
another
cell....

Should I do this in the ItemDataBound event of the
datagrid...something
like...
If e.Item.Cells(8).Text = "2" Then
dont allow the textbox defined in the
EditItemTemplate
to
be
visible
what is the code for this?
End If

Thanks for your help
 
NH said:
thanks for the reply.

I get a "Object reference not set to an instance of an object" error with
the line
CType(e.Item.FindControl("txtDaysWriteOffed"), TextBox).Visible = False

Should the EditItemTemplate control be referenceable in the ItemDataBound
datagrid event? Its as if it doesnt know about the control?

The control only exists when e.Item.ItemType = ListItemType.EditItem. The
ItemDataBound event is triggered for all ListItemTypes but your textbox only
exists for the EditItem.

All you need to do is just add an if statement like this:
If e.Item.ItemType = ListItemType.EditItem Then
If Not e.Item.FindControl("txtDaysWriteOffed") is Nothing then
CType(e.Item.FindControl("txtDaysWriteOffed"), TextBox).Visible =
False
End If
End If
 
Just posting here to keep your other post clean

Can you post me some of your code?
This really shouldn't be so difficult - certainly not a 48 hour problem

Grant Merwitz said:
Sorry man, all out of ideas and time .. home time

Try start a new post, as not many people will look at this one again - its
massive :)

Good luck

NH said:
Hi Grant,
I really appreciate all your effort on this. I really need to keep the
column visible, its just the txtbox in the EditItemTemplate. Anyway of
doin
it?

Grant Merwitz said:
GOT IT

After much fighting with Visual Studio - which kept removing my DataGrid
events, i found a way
In your EditCommand method, hide the Column you don't want to show,

So, if the TextBox will appear in Column 4, in you EditCommand Method do
as
follows:

private void DataGrid1_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

DatGrid1.EditItemIndex = e.Item.ItemIndex;

BindTopicGrid(this.m_user);

if(e.Item.Cells(8).Text = "2" then

DataGrid1.Columns[4].Visible = false;

End If

}

Again, HTH

tried that too, go the same object not set...error

This should be a simple thing to do, any other ideas? I am tried
everything
I know...

:

How about if you try that code in the EditCommand

private void DataGrid1_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

e.Item.FindControl("");

}



not sure the VB code for that, but accessed through the DataGrid
property
'EditCommand'


Yeah this is something I tried also, get an ""Object reference not
set
to
an
instance of an object" error.

It looks like the EditItemTemplate control is not referenceabnle in
the
ItemDataBound event?

:

sorry, drop out the control bit

e.Item.FindControl("MyControl")


Yes I tried that but it says "FindControl" is not a member of
System.Web.UI.ControlCollection"

thanks

:

i think it should be

CType(e.Item.Controls.FindControl("txtDaysWriteOffed"),
TextBox).Enabled
=
False

Adding the 'FindControl' in there

the line its failing on is
CType(e.Item.Controls("txtDaysWriteOffed"), TextBox).Enabled
=
False

Its says "Input string was not in a correct format. "

:

thanks for the reply.

I get a "Object reference not set to an instance of an
object"
error
with
the line
CType(e.Item.FindControl("txtDaysWriteOffed"),
TextBox).Visible
=
False

Should the EditItemTemplate control be referenceable in the
ItemDataBound
datagrid event? Its as if it doesnt know about the control?

:

e.Item.Controls.FindControl("TextBox's Id").Visible =
false;



How can I only display the textbox I have in an
EditItemTemplate
based on
the
value in another cell in the row?

i.e I only want users to edit one of the cells based on
the
value
in
another
cell....

Should I do this in the ItemDataBound event of the
datagrid...something
like...
If e.Item.Cells(8).Text = "2" Then
dont allow the textbox defined in the
EditItemTemplate
to
be
visible
what is the code for this?
End If

Thanks for your help
 

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

Back
Top