DataGrid write to Textbox in ItemDataBound help.

J

Jay

Hopefully someone can help me with this.
I have a datagrid that has many textboxes that when you go in are
empty and users can enter info in them and submit.
I now have added the ablity to save what you enter to recall it later.
There is a Textbox called ExtPrice that uses some javascript to
multiple quantity by Price and fill out this textbox.
When I load from the saved file this data is not stored so I figured
no problem I will fill it in on the DataBound however I can not get
access to this Textbox.
POLoad is a bool that is set to true when they load from a saved file.
Just useing the "1" to try and write anything at this point.

Here is the datagrid column.

<asp:TemplateColumn HeaderText="Ext. Price">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle Font-Size="XX-Small" Font-Names="Arial" Font-Bold="True"
HorizontalAlign="Right" VerticalAlign="Middle"
BackColor="Gainsboro"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="ExtPrice" ReadOnly="True" TabIndex="-5"
EnableViewState="True" Runat="server" Columns="7" />
</ItemTemplate>
</asp:TemplateColumn>

Code I have tried...

private void DataGrid_ItemDataBound(object s, DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if (POLoad && itemType != ListItemType.Header)
{
TextBox Edit = (TextBox)e.Item.FindControl("ExtPrice");
Edit.Text = "1";
}
}


Next Idea...

private void DataGrid_ItemDataBound(object s, DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if (POLoad && itemType != ListItemType.Header)
{

e.Item.Cells[6].Controls.Remove((TextBox)e.Item.FindControl("ExtPrice"));

TextBox ExtPrice = new TextBox(); ExtPrice.Text = "1";

e.Item.Cells[6].Controls.Add(ExtPrice);

}
}


I can get a 1 to appear in the cells if I do this....

private void DataGrid_ItemDataBound(object s, DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;

if (POLoad && itemType != ListItemType.Header)
{

e.Item.Cells[6].Text = "1";

}
}

But I need the textbox in case people make changes to the Price and
Quanitity...

Any help would me very much appricated!

Thanks
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top