Thursday, March 22, 2012

Text Value in a TextBox inside Datagrid

i have a textbox in a template column in a datagrid, it displays the
initial value of the row, but when i change it remains with the
original value (it doesnt get the new value..)
i fill the CartTable programmatically with rows from a database binded
datagrid..
i cant figure out what is wroooong! hehe thanks for helping
here is my code:
TABLE CODE (in the page_load):
If Session("shop_cart") Is Nothing Then
CartTable = New DataTable
CartTable.Columns.Add(New DataColumn("Product", GetType(String)))
CartTable.Columns.Add(New DataColumn("Line", GetType(String)))
CartTable.Columns.Add(New DataColumn("Description", GetType(String)))
CartTable.Columns.Add(New DataColumn("Quantity", GetType(String)))
CartTable.Columns.Add(New DataColumn("Price", GetType(String)))
CartTable.Columns.Add(New DataColumn("Total", GetType(String)))
ession("shop_cart") = CartTable
Else
CartTable = Session("shop_cart")
End If
BindBuy() 'this assign the datasource and execute DataBind()
DATAGRID CODE:
<asp:datagrid id="dgBuy" style="Z-INDEX: 103; LEFT: 80px; POSITION:
absolute; TOP: 576px" runat="server"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
BackColor="White" CellPadding="3"
Width="712px" AllowPaging="True" Font-Names="Tahoma"
Font-Size="X-Small" AutoGenerateColumns="False">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#669999"></SelectedItemStyle>
<ItemStyle ForeColor="#000066"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#006699"></HeaderStyle>
<FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
<Columns>
<asp:ButtonColumn Text="Delete"
CommandName="Delete"></asp:ButtonColumn>
<asp:BoundColumn DataField="Product"
HeaderText="Product"></asp:BoundColumn>
<asp:BoundColumn DataField="Line"
HeaderText="Line"></asp:BoundColumn>
<asp:BoundColumn DataField="Description"
HeaderText="Description"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox id=txtQty runat="server" Width="40px" Text='<%#
DataBinder.Eval(Container.DataItem, "Quantity") %>' >
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Price" HeaderText="Price"
DataFormatString="{0:c}"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Total">
<ItemTemplate>
<p>
<asp:Label runat="server" Text='<%#
System.String.Format("{0:c}",CalcTotal(Int32.Parse(DataBinder.Eval(Container
.DataItem,
"Quantity")),DataBinder.Eval(Container.DataItem, "Price"))) %>'
ID="Label8"/>
</p>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Left" ForeColor="#000066"
BackColor="Silver" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
UPDATE BUTTON CODE:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim i As Integer
Dim _item As DataGridItem
Dim dr As DataRow
For i = 0 To dgBuy.Items.Count - 1
_item = dgBuy.Items(i)
Dim qtyTextBox As TextBox = _item.FindControl("txtQty")
dr = CartTable.Rows(i)
dr(3) = qtyTextBox.Text
Next
BindBuy()
End SubMake sure viewstate is on the page. Also, likely you'll only want to
populate the grid when "not page.ispostback", otherwise you'll be overwritin
g
any changes made to the data in the boxes.
"ismaelf@.gmail.com" wrote:

> i have a textbox in a template column in a datagrid, it displays the
> initial value of the row, but when i change it remains with the
> original value (it doesnt get the new value..)
> i fill the CartTable programmatically with rows from a database binded
> datagrid..
> i cant figure out what is wroooong! hehe thanks for helping
> here is my code:
> TABLE CODE (in the page_load):
> If Session("shop_cart") Is Nothing Then
> CartTable = New DataTable
> CartTable.Columns.Add(New DataColumn("Product", GetType(String)))
> CartTable.Columns.Add(New DataColumn("Line", GetType(String)))
> CartTable.Columns.Add(New DataColumn("Description", GetType(String)))
> CartTable.Columns.Add(New DataColumn("Quantity", GetType(String)))
> CartTable.Columns.Add(New DataColumn("Price", GetType(String)))
> CartTable.Columns.Add(New DataColumn("Total", GetType(String)))
> ession("shop_cart") = CartTable
> Else
> CartTable = Session("shop_cart")
> End If
> BindBuy() 'this assign the datasource and execute DataBind()
>
> DATAGRID CODE:
> <asp:datagrid id="dgBuy" style="Z-INDEX: 103; LEFT: 80px; POSITION:
> absolute; TOP: 576px" runat="server"
> BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
> BackColor="White" CellPadding="3"
> Width="712px" AllowPaging="True" Font-Names="Tahoma"
> Font-Size="X-Small" AutoGenerateColumns="False">
> <SelectedItemStyle Font-Bold="True" ForeColor="White"
> BackColor="#669999"></SelectedItemStyle>
> <ItemStyle ForeColor="#000066"></ItemStyle>
> <HeaderStyle Font-Bold="True" ForeColor="White"
> BackColor="#006699"></HeaderStyle>
> <FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
> <Columns>
> <asp:ButtonColumn Text="Delete"
> CommandName="Delete"></asp:ButtonColumn>
> <asp:BoundColumn DataField="Product"
> HeaderText="Product"></asp:BoundColumn>
> <asp:BoundColumn DataField="Line"
> HeaderText="Line"></asp:BoundColumn>
> <asp:BoundColumn DataField="Description"
> HeaderText="Description"></asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Quantity">
> <ItemTemplate>
> <asp:TextBox id=txtQty runat="server" Width="40px" Text='<%#
> DataBinder.Eval(Container.DataItem, "Quantity") %>' >
> </asp:TextBox>
> </ItemTemplate>
> </asp:TemplateColumn>
> <asp:BoundColumn DataField="Price" HeaderText="Price"
> DataFormatString="{0:c}"></asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Total">
> <ItemTemplate>
> <p>
> <asp:Label runat="server" Text='<%#
> System.String.Format("{0:c}",CalcTotal(Int32.Parse(DataBinder.Eval(Contain
er.DataItem,
> "Quantity")),DataBinder.Eval(Container.DataItem, "Price"))) %>'
> ID="Label8"/>
> </p>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> <PagerStyle HorizontalAlign="Left" ForeColor="#000066"
> BackColor="Silver" Mode="NumericPages"></PagerStyle>
> </asp:datagrid>
> UPDATE BUTTON CODE:
> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button2.Click
> Dim i As Integer
> Dim _item As DataGridItem
> Dim dr As DataRow
> For i = 0 To dgBuy.Items.Count - 1
> _item = dgBuy.Items(i)
> Dim qtyTextBox As TextBox = _item.FindControl("txtQty")
> dr = CartTable.Rows(i)
> dr(3) = qtyTextBox.Text
> Next
> BindBuy()
> End Sub
>
thanks, i populate the table under not page.ispostback now.. and verify
the ViewState also and its enabled.. but i still have the same problem
of the textbox.. :(

0 comments:

Post a Comment