|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Change/read value from control in EditItemTemplateIn my datagrid I have a textbox in an EditItemTemplate like so -------------------- <asp:TextBox id=txtPrice ontextchanged="txtPrice_TextChanged" runat="server" AutoPostBack="True"> -------------------- I also have back end code like this: -------------------- Sub txtPrice_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Response.Write("BOING!") 'This won't get the textbox controls I need, what should I do? 'Dim txtPrice As TextBox =MyDataGrid.Items(e.Item.ItemIndex).FindControl("txtPrice") 'Dim txtDiscount As TextBox = MyDataGrid.Items(e.Item.ItemIndex).FindControl("txtDiscount") 'Dim txtTotal As TextBox = MyDataGrid.Items(e.Item.ItemIndex).FindControl("txtTotal") End Sub -------------------- This code works fine (Note I've remmed out the last three lines). I basically need to get control of the textbox controls in the edititem template so I can get their values and update them. If I take out the rems it won't work (e points to system.eventargs, not WebControls.DataGridCommandEventArgs). So I need something else. What code do I need to get control of the textboxes in edititemtemplate? Many thanks! Alex In the TextChanged event handler sender is the TextBox control that
caused the event. So, you can get a reference to the TextBox using: Dim myTB as TextBox = CType(sender, TextBox) hth posti***@alexshirley.com wrote: Show quoteHide quote > Hi > > In my datagrid I have a textbox in an EditItemTemplate like so > > -------------------- > <asp:TextBox id=txtPrice ontextchanged="txtPrice_TextChanged" > runat="server" AutoPostBack="True"> > -------------------- > > I also have back end code like this: > > > -------------------- > Sub txtPrice_TextChanged(ByVal sender As System.Object, ByVal e As > System.EventArgs) > Response.Write("BOING!") > > 'This won't get the textbox controls I need, what should I do? > 'Dim txtPrice As TextBox > =MyDataGrid.Items(e.Item.ItemIndex).FindControl("txtPrice") > 'Dim txtDiscount As TextBox = > MyDataGrid.Items(e.Item.ItemIndex).FindControl("txtDiscount") > 'Dim txtTotal As TextBox = > MyDataGrid.Items(e.Item.ItemIndex).FindControl("txtTotal") > > End Sub > -------------------- > > This code works fine (Note I've remmed out the last three lines). > > I basically need to get control of the textbox controls in the edititem > template so I can get their values and update them. > > If I take out the rems it won't work (e points to system.eventargs, > not WebControls.DataGridCommandEventArgs). So I need something else. > > What code do I need to get control of the textboxes in > edititemtemplate? > > Many thanks! > > Alex > Thanks Scott (sorry I've been away fixing another datagrid problem
before I could get back to this one!)... This works great (doh I should have realised this! - thanks)... I now get the value of the textbox now, from my subroutine triggered via autopostback: >Dim myTB as TextBox = CType(sender, TextBox) I now need to get the values of other textboxes inside the datagrid,and update the value of another textbox inside the datagrid - from this same subroutine which is triggered by autopostback. How can I get the values of these controls form the datagrid? Cheers! Alex posti***@alexshirley.com wrote:
Show quoteHide quote > Thanks Scott (sorry I've been away fixing another datagrid problem I trust you know how to get the controls when you have a reference to > before I could get back to this one!)... > > This works great (doh I should have realised this! - thanks)... > I now get the value of the textbox now, from my subroutine triggered > via autopostback: > > >>Dim myTB as TextBox = CType(sender, TextBox) > > > I now need to get the values of other textboxes inside the datagrid, > and update the value of another textbox inside the datagrid - from this > same subroutine which is triggered by autopostback. > > How can I get the values of these controls form the datagrid? the DataGridItem? If so, you can get the DataGridItem that contains the TextBox using the following code: Dim dgi as DataGridItem = CType(myTB.Parent.Parent, DataGridItem) hth Thanks Scott (sorry I've been away fixing another datagrid problem
before I could get back to this one!)... This works great (doh I should have realised this! - thanks)... I now get the value of the textbox now, from my subroutine triggered via autopostback: >Dim myTB as TextBox = CType(sender, TextBox) I now need to get the values of other textboxes inside the datagrid,and update the value of another textbox inside the datagrid - from this same subroutine which is triggered by autopostback. How can I get the values of these controls from the datagrid? Cheers! Alex
Paging with Datagrid Control
how can I get the DataKeyField Howto insert delete rows into a ASP.net datagrid? read row values from datagrid and populate in new datagrid values from connected Accessing data object on delete command. Datagrid paging keeps going back to the first group MessageBox not showing before Response.Redirect ItemDataBound Slow datagrid on postback how to use hyper columns in datagrid |
|||||||||||||||||||||||