Asp.net Insert into Datagrid Textbox

geraint

Newcomer
Joined
Jan 13, 2005
Messages
1
Hi,

I wanted to add the following question to error bank:

I have a datagrid containing template columns which allow editing of the values contained in the datagrid through the use of text boxes.

One of the fields in the datagrid displays the time and date.

When a row has been selected for editing I want to be able to click a button in the datagrid and update one of the text boxes with the current time and date.

All the code for editing rows and getting the current time and date when you click a button works fine. My only problem is inserting the current date and time into the text box within the selected row of the datagrid.

I can get the value of the text box OUT of the datagrid by calling the function below from the datagrid:

void UpdateTime(Object sender, DataGridCommandEventArgs e){

TextBox StartTime = (TextBox)e.Item.Cells[2].FindControl("UpdateStartTime");
Response.Write("Start Time = "+StartTime.Text);
Response.Flush();

}

But I just can't put a value INTO the text box in the datagrid.

I've tried lots of variations of commands, but none of them seem to work!

Any ideas?

Thanks in advance
 
Anyone?

Does anyone have any suggestions for this issue? I'm having the same problem. I need to put a value into a textbox in a datagrid, not just retrieve the value....

Kahuna
 
How aboout updating the datasource with the new info, then rebind the datagrid. I think your datagrid control's value is not "keeping" becuase of this.
 
geraint said:
Hi,

I wanted to add the following question to error bank:

I have a datagrid containing template columns which allow editing of the values contained in the datagrid through the use of text boxes.

One of the fields in the datagrid displays the time and date.

When a row has been selected for editing I want to be able to click a button in the datagrid and update one of the text boxes with the current time and date.

All the code for editing rows and getting the current time and date when you click a button works fine. My only problem is inserting the current date and time into the text box within the selected row of the datagrid.

I can get the value of the text box OUT of the datagrid by calling the function below from the datagrid:

void UpdateTime(Object sender, DataGridCommandEventArgs e){

TextBox StartTime = (TextBox)e.Item.Cells[2].FindControl("UpdateStartTime");
Response.Write("Start Time = "+StartTime.Text);
Response.Flush();

}

But I just can't put a value INTO the text box in the datagrid.

I've tried lots of variations of commands, but none of them seem to work!

Any ideas?

Thanks in advance
Here's the VB code:

Visual Basic:
[size=2][color=#0000ff]CType[/color][/size][size=2](e.Item.Cells(4).FindControl("txtQty"), TextBox).Text = " "
[/size]

You would, of course, need to put this into C# (a language I'm not familiar with). Instead of extracting the value of the textbox, you assign it.

Hope this helps!

Kahuna

 
SteveoAtilla said:
Here's the VB code:

Visual Basic:
[size=2][color=#0000ff]CType[/color][/size][size=2](e.Item.Cells(4).FindControl("txtQty"), TextBox).Text = " "
[/size]

You would, of course, need to put this into C# (a language I'm not familiar with). Instead of extracting the value of the textbox, you assign it.

Hope this helps!

Kahuna

Alternately, a variable can be created and used to avoid the CType command:

Visual Basic:
[size=2][color=#0000ff]Dim[/color][/size][size=2] box [/size][size=2][color=#0000ff]As[/color][/size][size=2] TextBox[/size]
[size=2]box = [/size][size=2][color=#0000ff]CType[/color][/size][size=2](e.Item.Cells(4).FindControl("txtQty"), TextBox)[/size]
[size=2]box.text = " "
[/size]

This results in the same thing, but would be cleaner if you repeatedly needed to refer to the textbox.

Kahuna
 
Back
Top