Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If i've understood you correctly, you want a TextBox in the price-column and a textbox for the total price. You could use a TemplateColumn to show the price in a textbox and the footer to show the totalprice. </p> <p>ASPX:</p> <pre><code> &lt;asp:GridView ID="GridView1" runat="server" ShowFooter="true" AutoGenerateColumns="false" &gt; &lt;Columns&gt; &lt;asp:BoundField HeaderText="ID" DataField="Name" /&gt; &lt;asp:BoundField HeaderText="Name" DataField="Name" /&gt; &lt;asp:TemplateField HeaderText="Price(Grouch)/Hectares"&gt; &lt;ItemTemplate&gt; &lt;asp:TextBox ID="TxtPrice" runat="server"&gt;&lt;/asp:TextBox&gt; &lt;/ItemTemplate&gt; &lt;FooterTemplate&gt; &lt;asp:TextBox ID="TxtTotal" runat="server" Text="0"&gt;&lt;/asp:TextBox&gt; &lt;/FooterTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>Sorry for VB.Net, i hope you see what i mean anyway, the importan part is in <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx" rel="nofollow">RowDataBound</a> of the GridView:</p> <pre><code> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then BindGrid() End If End Sub Private Sub BindGrid() Dim dt As New DataTable dt.Columns.Add("ID", GetType(Int32)).AutoIncrement = True dt.Columns.Add("Name", GetType(String)) dt.Columns.Add("Price(Grouch)/Hectares", GetType(Single)) dt.PrimaryKey = New DataColumn() {dt.Columns("ID")} Dim newRow As DataRow = dt.NewRow newRow("ID") = 1 newRow("Name") = "Seaside Location" newRow("Price(Grouch)/Hectares") = 1.5 dt.Rows.Add(newRow) newRow = dt.NewRow newRow("ID") = 2 newRow("Name") = "City Location" newRow("Price(Grouch)/Hectares") = 7.9 dt.Rows.Add(newRow) Me.GridView1.DataSource = dt Me.GridView1.DataBind() End Sub Private totalPrice As Single = 0 Private Sub GridRowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then Dim row As DataRow = DirectCast(e.Row.DataItem, DataRowView).Row Dim txtPrice As TextBox = DirectCast(e.Row.FindControl("TxtPrice"), TextBox) Dim price As Single = DirectCast(row("Price(Grouch)/Hectares"), Single) txtPrice.Text = price.ToString totalPrice = totalPrice + price ElseIf e.Row.RowType = DataControlRowType.Footer Then Dim txtTotal As TextBox = DirectCast(e.Row.FindControl("TxtTotal"), TextBox) txtTotal.Text = totalPrice.ToString End If End Sub </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload