Showing posts with label displays. Show all posts
Showing posts with label displays. Show all posts

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.. :(

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 align="right">
<asp:Label runat="server" Text='<%#
System.String.Format("{0:c}",CalcTotal(Int32.Parse(DataBinder.Eval(Container.D ataItem,
"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 overwriting
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 align="right">
> <asp:Label runat="server" Text='<%#
> System.String.Format("{0:c}",CalcTotal(Int32.Parse(DataBinder.Eval(Container.D ataItem,
> "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.. :(

textarea viewstate formatting

Hello.

What I am trying to do is implement a "preview" function that displays all of the html typed within a textarea onto a webpage with HTML intact. I am using the viewstate to preserve the contents of the textarea. However, I find that doing this replaces all "<" with "<", ">" with ">". As a result, the preview does not render any HTML.

It appears that viewstate with asp.net automatically converts the chars, perhaps as insurance to "sterilize" malicious script. Can someone confirm this?

Is there a way to prevent it from converting the carat characters for the viewState preservation? Or is it a fact of life that I'll need to manually convert them back?

Thanks,
walla118Thanks niceguy.

I just realized that HtmlDecode would work for my purposes. And your idea about using javascript to display preview might be a good way to go!

Thanks again.
Hi walla118,

Have you tried using:


HttpContext.Current.Server.HtmlEncode
HttpContext.Current.Server.HtmlDecode

These may help...?

I found that it is easier to open a pop-up using javascript for a "preview" rather than doing it server side...just a thought.

Hope this helps!

Jason