Code:
<asp:GridView ID="productsGridView" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="3" OnRowCommand="productsGridView_RowCommand" >
<FooterStyle BackColor="White" ForeColor="#000066" />
<RowStyle ForeColor="#000066" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="Product Name" />
<asp:BoundField DataField="Price" HeaderText="Price" />
<asp:TemplateField HeaderText="Number">
<ItemTemplate>
<asp:TextBox ID="TextBox1" Text="0" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="addToChart" HeaderText="Add to chart"
Text="Add" />
</Columns>
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:GridView ID="productsGridView" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="3" OnRowCommand="productsGridView_RowCommand" >
<FooterStyle BackColor="White" ForeColor="#000066" />
<RowStyle ForeColor="#000066" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="Product Name" />
<asp:BoundField DataField="Price" HeaderText="Price" />
<asp:TemplateField HeaderText="Number">
<ItemTemplate>
<asp:TextBox ID="TextBox1" Text="0" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="addToChart" HeaderText="Add to chart"
Text="Add" />
</Columns>
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
Ovako citam vrednost textboxa:
Code:
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = productsGridView.Rows[index];
TextBox tb = (TextBox) selectedRow.Cells[2].FindControl("TextBox1");
Message.Text = tb.Text; // Message je samo jedna labela
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = productsGridView.Rows[index];
TextBox tb = (TextBox) selectedRow.Cells[2].FindControl("TextBox1");
Message.Text = tb.Text; // Message je samo jedna labela
Problem je sto on uvjek vraca default vrednost. Vjerovatno je neka sitnica , ali stvarno nemam iskustva sa ASP da bih je uocio. :)
Free advice is seldom cheap.