473,387 Members | 1,535 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,387 software developers and data experts.

EditItemTemplate question

NH
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
Nov 19 '05 #1
15 1583
e.Item.Controls.FindControl("TextBox's Id").Visible = false;

"NH" <NH@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
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

Nov 19 '05 #2
NH
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?

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

"NH" <NH@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
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


Nov 19 '05 #3
NH
the line its failing on is
CType(e.Item.Controls("txtDaysWriteOffed"), TextBox).Enabled = False

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

"NH" wrote:
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?

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

"NH" <NH@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
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


Nov 19 '05 #4
i think it should be

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

Adding the 'FindControl' in there

"NH" <NH@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
the line its failing on is
CType(e.Item.Controls("txtDaysWriteOffed"), TextBox).Enabled = False

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

"NH" wrote:
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?

"Grant Merwitz" wrote:
> e.Item.Controls.FindControl("TextBox's Id").Visible = false;
>
>
>
> "NH" <NH@discussions.microsoft.com> wrote in message
> news:E4**********************************@microsof t.com...
> > 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
>
>
>

Nov 19 '05 #5
NH
Yes I tried that but it says "FindControl" is not a member of
System.Web.UI.ControlCollection"

thanks

"Grant Merwitz" wrote:
i think it should be

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

Adding the 'FindControl' in there

"NH" <NH@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
the line its failing on is
CType(e.Item.Controls("txtDaysWriteOffed"), TextBox).Enabled = False

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

"NH" wrote:
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?

"Grant Merwitz" wrote:

> e.Item.Controls.FindControl("TextBox's Id").Visible = false;
>
>
>
> "NH" <NH@discussions.microsoft.com> wrote in message
> news:E4**********************************@microsof t.com...
> > 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
>
>
>


Nov 19 '05 #6
sorry, drop out the control bit

e.Item.FindControl("MyControl")
"NH" <NH@discussions.microsoft.com> wrote in message
news:BD**********************************@microsof t.com...
Yes I tried that but it says "FindControl" is not a member of
System.Web.UI.ControlCollection"

thanks

"Grant Merwitz" wrote:
i think it should be

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

Adding the 'FindControl' in there

"NH" <NH@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
> the line its failing on is
> CType(e.Item.Controls("txtDaysWriteOffed"), TextBox).Enabled = False
>
> Its says "Input string was not in a correct format. "
>
> "NH" wrote:
>
>> 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?
>>
>> "Grant Merwitz" wrote:
>>
>> > e.Item.Controls.FindControl("TextBox's Id").Visible = false;
>> >
>> >
>> >
>> > "NH" <NH@discussions.microsoft.com> wrote in message
>> > news:E4**********************************@microsof t.com...
>> > > 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
>> >
>> >
>> >


Nov 19 '05 #7
NH
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?

"Grant Merwitz" wrote:
sorry, drop out the control bit

e.Item.FindControl("MyControl")
"NH" <NH@discussions.microsoft.com> wrote in message
news:BD**********************************@microsof t.com...
Yes I tried that but it says "FindControl" is not a member of
System.Web.UI.ControlCollection"

thanks

"Grant Merwitz" wrote:
i think it should be

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

Adding the 'FindControl' in there

"NH" <NH@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
> the line its failing on is
> CType(e.Item.Controls("txtDaysWriteOffed"), TextBox).Enabled = False
>
> Its says "Input string was not in a correct format. "
>
> "NH" wrote:
>
>> 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?
>>
>> "Grant Merwitz" wrote:
>>
>> > e.Item.Controls.FindControl("TextBox's Id").Visible = false;
>> >
>> >
>> >
>> > "NH" <NH@discussions.microsoft.com> wrote in message
>> > news:E4**********************************@microsof t.com...
>> > > 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
>> >
>> >
>> >


Nov 19 '05 #8
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'
"NH" <NH@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
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?

"Grant Merwitz" wrote:
sorry, drop out the control bit

e.Item.FindControl("MyControl")
"NH" <NH@discussions.microsoft.com> wrote in message
news:BD**********************************@microsof t.com...
> Yes I tried that but it says "FindControl" is not a member of
> System.Web.UI.ControlCollection"
>
> thanks
>
> "Grant Merwitz" wrote:
>
>> i think it should be
>>
>> CType(e.Item.Controls.FindControl("txtDaysWriteOff ed"),
>> TextBox).Enabled
>> =
>> False
>>
>> Adding the 'FindControl' in there
>>
>> "NH" <NH@discussions.microsoft.com> wrote in message
>> news:D1**********************************@microsof t.com...
>> > the line its failing on is
>> > CType(e.Item.Controls("txtDaysWriteOffed"), TextBox).Enabled = False
>> >
>> > Its says "Input string was not in a correct format. "
>> >
>> > "NH" wrote:
>> >
>> >> 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?
>> >>
>> >> "Grant Merwitz" wrote:
>> >>
>> >> > e.Item.Controls.FindControl("TextBox's Id").Visible = false;
>> >> >
>> >> >
>> >> >
>> >> > "NH" <NH@discussions.microsoft.com> wrote in message
>> >> > news:E4**********************************@microsof t.com...
>> >> > > 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
>> >> >
>> >> >
>> >> >
>>
>>
>>


Nov 19 '05 #9
NH
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!!

"Grant Merwitz" wrote:
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'
"NH" <NH@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
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?

"Grant Merwitz" wrote:
sorry, drop out the control bit

e.Item.FindControl("MyControl")
"NH" <NH@discussions.microsoft.com> wrote in message
news:BD**********************************@microsof t.com...
> Yes I tried that but it says "FindControl" is not a member of
> System.Web.UI.ControlCollection"
>
> thanks
>
> "Grant Merwitz" wrote:
>
>> i think it should be
>>
>> CType(e.Item.Controls.FindControl("txtDaysWriteOff ed"),
>> TextBox).Enabled
>> =
>> False
>>
>> Adding the 'FindControl' in there
>>
>> "NH" <NH@discussions.microsoft.com> wrote in message
>> news:D1**********************************@microsof t.com...
>> > the line its failing on is
>> > CType(e.Item.Controls("txtDaysWriteOffed"), TextBox).Enabled = False
>> >
>> > Its says "Input string was not in a correct format. "
>> >
>> > "NH" wrote:
>> >
>> >> 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?
>> >>
>> >> "Grant Merwitz" wrote:
>> >>
>> >> > e.Item.Controls.FindControl("TextBox's Id").Visible = false;
>> >> >
>> >> >
>> >> >
>> >> > "NH" <NH@discussions.microsoft.com> wrote in message
>> >> > news:E4**********************************@microsof t.com...
>> >> > > 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
>> >> >
>> >> >
>> >> >
>>
>>
>>


Nov 19 '05 #10
NH
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...

"Grant Merwitz" wrote:
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'
"NH" <NH@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
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?

"Grant Merwitz" wrote:
sorry, drop out the control bit

e.Item.FindControl("MyControl")
"NH" <NH@discussions.microsoft.com> wrote in message
news:BD**********************************@microsof t.com...
> Yes I tried that but it says "FindControl" is not a member of
> System.Web.UI.ControlCollection"
>
> thanks
>
> "Grant Merwitz" wrote:
>
>> i think it should be
>>
>> CType(e.Item.Controls.FindControl("txtDaysWriteOff ed"),
>> TextBox).Enabled
>> =
>> False
>>
>> Adding the 'FindControl' in there
>>
>> "NH" <NH@discussions.microsoft.com> wrote in message
>> news:D1**********************************@microsof t.com...
>> > the line its failing on is
>> > CType(e.Item.Controls("txtDaysWriteOffed"), TextBox).Enabled = False
>> >
>> > Its says "Input string was not in a correct format. "
>> >
>> > "NH" wrote:
>> >
>> >> 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?
>> >>
>> >> "Grant Merwitz" wrote:
>> >>
>> >> > e.Item.Controls.FindControl("TextBox's Id").Visible = false;
>> >> >
>> >> >
>> >> >
>> >> > "NH" <NH@discussions.microsoft.com> wrote in message
>> >> > news:E4**********************************@microsof t.com...
>> >> > > 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
>> >> >
>> >> >
>> >> >
>>
>>
>>


Nov 19 '05 #11
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" <NH@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
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...

"Grant Merwitz" wrote:
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'
"NH" <NH@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
> 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?
>
> "Grant Merwitz" wrote:
>
>> sorry, drop out the control bit
>>
>> e.Item.FindControl("MyControl")
>>
>>
>> "NH" <NH@discussions.microsoft.com> wrote in message
>> news:BD**********************************@microsof t.com...
>> > Yes I tried that but it says "FindControl" is not a member of
>> > System.Web.UI.ControlCollection"
>> >
>> > thanks
>> >
>> > "Grant Merwitz" wrote:
>> >
>> >> i think it should be
>> >>
>> >> CType(e.Item.Controls.FindControl("txtDaysWriteOff ed"),
>> >> TextBox).Enabled
>> >> =
>> >> False
>> >>
>> >> Adding the 'FindControl' in there
>> >>
>> >> "NH" <NH@discussions.microsoft.com> wrote in message
>> >> news:D1**********************************@microsof t.com...
>> >> > the line its failing on is
>> >> > CType(e.Item.Controls("txtDaysWriteOffed"), TextBox).Enabled =
>> >> > False
>> >> >
>> >> > Its says "Input string was not in a correct format. "
>> >> >
>> >> > "NH" wrote:
>> >> >
>> >> >> 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?
>> >> >>
>> >> >> "Grant Merwitz" wrote:
>> >> >>
>> >> >> > e.Item.Controls.FindControl("TextBox's Id").Visible = false;
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > "NH" <NH@discussions.microsoft.com> wrote in message
>> >> >> > news:E4**********************************@microsof t.com...
>> >> >> > > 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
>> >> >> >
>> >> >> >
>> >> >> >
>> >>
>> >>
>> >>
>>
>>
>>


Nov 19 '05 #12
NH
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" wrote:
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" <NH@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
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...

"Grant Merwitz" wrote:
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'
"NH" <NH@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
> 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?
>
> "Grant Merwitz" wrote:
>
>> sorry, drop out the control bit
>>
>> e.Item.FindControl("MyControl")
>>
>>
>> "NH" <NH@discussions.microsoft.com> wrote in message
>> news:BD**********************************@microsof t.com...
>> > Yes I tried that but it says "FindControl" is not a member of
>> > System.Web.UI.ControlCollection"
>> >
>> > thanks
>> >
>> > "Grant Merwitz" wrote:
>> >
>> >> i think it should be
>> >>
>> >> CType(e.Item.Controls.FindControl("txtDaysWriteOff ed"),
>> >> TextBox).Enabled
>> >> =
>> >> False
>> >>
>> >> Adding the 'FindControl' in there
>> >>
>> >> "NH" <NH@discussions.microsoft.com> wrote in message
>> >> news:D1**********************************@microsof t.com...
>> >> > the line its failing on is
>> >> > CType(e.Item.Controls("txtDaysWriteOffed"), TextBox).Enabled =
>> >> > False
>> >> >
>> >> > Its says "Input string was not in a correct format. "
>> >> >
>> >> > "NH" wrote:
>> >> >
>> >> >> 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?
>> >> >>
>> >> >> "Grant Merwitz" wrote:
>> >> >>
>> >> >> > e.Item.Controls.FindControl("TextBox's Id").Visible = false;
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > "NH" <NH@discussions.microsoft.com> wrote in message
>> >> >> > news:E4**********************************@microsof t.com...
>> >> >> > > 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
>> >> >> >
>> >> >> >
>> >> >> >
>> >>
>> >>
>> >>
>>
>>
>>


Nov 19 '05 #13
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" <NH@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
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" wrote:
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" <NH@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
> 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...
>
> "Grant Merwitz" wrote:
>
>> 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'
>>
>>
>> "NH" <NH@discussions.microsoft.com> wrote in message
>> news:98**********************************@microsof t.com...
>> > 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?
>> >
>> > "Grant Merwitz" wrote:
>> >
>> >> sorry, drop out the control bit
>> >>
>> >> e.Item.FindControl("MyControl")
>> >>
>> >>
>> >> "NH" <NH@discussions.microsoft.com> wrote in message
>> >> news:BD**********************************@microsof t.com...
>> >> > Yes I tried that but it says "FindControl" is not a member of
>> >> > System.Web.UI.ControlCollection"
>> >> >
>> >> > thanks
>> >> >
>> >> > "Grant Merwitz" wrote:
>> >> >
>> >> >> i think it should be
>> >> >>
>> >> >> CType(e.Item.Controls.FindControl("txtDaysWriteOff ed"),
>> >> >> TextBox).Enabled
>> >> >> =
>> >> >> False
>> >> >>
>> >> >> Adding the 'FindControl' in there
>> >> >>
>> >> >> "NH" <NH@discussions.microsoft.com> wrote in message
>> >> >> news:D1**********************************@microsof t.com...
>> >> >> > the line its failing on is
>> >> >> > CType(e.Item.Controls("txtDaysWriteOffed"), TextBox).Enabled =
>> >> >> > False
>> >> >> >
>> >> >> > Its says "Input string was not in a correct format. "
>> >> >> >
>> >> >> > "NH" wrote:
>> >> >> >
>> >> >> >> 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?
>> >> >> >>
>> >> >> >> "Grant Merwitz" wrote:
>> >> >> >>
>> >> >> >> > e.Item.Controls.FindControl("TextBox's Id").Visible =
>> >> >> >> > false;
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > "NH" <NH@discussions.microsoft.com> wrote in message
>> >> >> >> > news:E4**********************************@microsof t.com...
>> >> >> >> > > 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
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>
>>
>>
>>


Nov 19 '05 #14

"NH" wrote:
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

---
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Grant Merwitz" wrote:
e.Item.Controls.FindControl("TextBox's Id").Visible = false;

"NH" <NH@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
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


Nov 19 '05 #15
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" <gr***@workshare.com> wrote in message
news:e9**************@TK2MSFTNGP09.phx.gbl...
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" <NH@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
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" wrote:
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" <NH@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
> 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...
>
> "Grant Merwitz" wrote:
>
>> 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'
>>
>>
>> "NH" <NH@discussions.microsoft.com> wrote in message
>> news:98**********************************@microsof t.com...
>> > 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?
>> >
>> > "Grant Merwitz" wrote:
>> >
>> >> sorry, drop out the control bit
>> >>
>> >> e.Item.FindControl("MyControl")
>> >>
>> >>
>> >> "NH" <NH@discussions.microsoft.com> wrote in message
>> >> news:BD**********************************@microsof t.com...
>> >> > Yes I tried that but it says "FindControl" is not a member of
>> >> > System.Web.UI.ControlCollection"
>> >> >
>> >> > thanks
>> >> >
>> >> > "Grant Merwitz" wrote:
>> >> >
>> >> >> i think it should be
>> >> >>
>> >> >> CType(e.Item.Controls.FindControl("txtDaysWriteOff ed"),
>> >> >> TextBox).Enabled
>> >> >> =
>> >> >> False
>> >> >>
>> >> >> Adding the 'FindControl' in there
>> >> >>
>> >> >> "NH" <NH@discussions.microsoft.com> wrote in message
>> >> >> news:D1**********************************@microsof t.com...
>> >> >> > the line its failing on is
>> >> >> > CType(e.Item.Controls("txtDaysWriteOffed"), TextBox).Enabled
>> >> >> > =
>> >> >> > False
>> >> >> >
>> >> >> > Its says "Input string was not in a correct format. "
>> >> >> >
>> >> >> > "NH" wrote:
>> >> >> >
>> >> >> >> 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?
>> >> >> >>
>> >> >> >> "Grant Merwitz" wrote:
>> >> >> >>
>> >> >> >> > e.Item.Controls.FindControl("TextBox's Id").Visible =
>> >> >> >> > false;
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > "NH" <NH@discussions.microsoft.com> wrote in message
>> >> >> >> > news:E4**********************************@microsof t.com...
>> >> >> >> > > 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
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>
>>
>>
>>


Nov 19 '05 #16

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

Similar topics

0
by: hasden | last post by:
I want to remotely load an edititemtemplate into a formview control. I am currently loading the item templates from .ascx files just fine and they run the <%# Eval() #> stuff and everything is...
5
by: Gene McCrory | last post by:
Is it possible to have a CustomValidator against two controls in an EditItemTemplate on a DataGrid? Case: Have a business rule that states if ATextBox starts with "ACertainValue" then BTextBox...
1
by: George Durzi | last post by:
When my datagrid is in edit mode, one of my columns is edited using a drop down list. I'm able to bind the DropDownList to a DataSource when in edit mode. HOWEVER, I can't preset the...
2
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: ...
4
by: Dabbler | last post by:
I have two tables I'm editing in a Gridview. The VANS table contains a key to the other LESSOR table. I would like to use a dropdown list to select the LessorId value while displaying the Lessor...
1
by: James | last post by:
Hi all. I'm struggling a bit with this so any help appreciated. (Framework 2.0, VB.net ) I have a text box within an EditItemTemplate, the value of which is bound to my GridView's datasource....
0
by: Dan | last post by:
Issue making textbox visible based on specific input from a radio button list in an EditItemTemplate I want to setup a gridview that when in edit mode and when the user selects "Other" from a...
2
by: Steve Hershoff | last post by:
Hi everyone, I have a DataGrid with several TemplateColumns. One of these columns has an EditItemTemplate that contains an ASP.Net DropDownList. I'm catching this DropDownList's...
0
by: dch | last post by:
I have a GridView, and when I click Edit, it is firing the OnRowEditing event ,and I am setting the edititem index, but it keeps displaying the ItemTemplate fields instead of the EditItemTemplate. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.