I'm working on a shopping cart in a website and I have my items(which have been added to the cart) in an arraylist. And using these values I've read the rest of the values from the db and and have populated on the gridview successfully.
if (d1.Read())
{
d1.Close();
sda.SelectCommand = searchResult;
sda.Fill(dt);
GridView2.DataSource = dt;
GridView2.DataBind();
}
How can I add an additional column named "Quantity" in this gridview along with a text box so that user can enter a value for the qunatity for each item displayed in the gridview?
Any help/suggestions/links would be greatly appreciated.
thanks,
//edit 2
<asp:GridView ID="GridView2" runat="server" BackColor="#388AD0"
BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black"
GridLines="Vertical" Height="160px" Style="left: 72px;
position: relative; top: 8px" Width="504px" AllowPaging="True" PageSize="5">
<FooterStyle BackColor="#E0E0E0" />
<PagerStyle BackColor="Silver" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#388AD0" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#388AD0" />
<PagerSettings Mode="NextPrevious" />
</asp:GridView>
//edit 3
public void additem(string additem)
{
DataTable dt = new DataTable();
string ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ewap_k.mdf;Integrated Security=True;User Instance=True";
using (SqlConnection searchCon = new SqlConnection(ConnectionString))
{
using (SqlCommand searchResult = new SqlCommand("SELECT ItemID, Name, RelDate, Price, Status FROM item_k WHERE ItemID IN ( " + itemIDs + ")", searchCon))
{
searchCon.Open();
SqlDataReader d1 = searchResult.ExecuteReader();
SqlDataAdapter sda = new SqlDataAdapter();
if (d1.Read())
{
d1.Close();
sda.SelectCommand = searchResult;
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
else { }
searchCon.Close();
}
}
}
//edit 4
<asp:GridView ID="GridView1" runat="server" Style="left: 8px; position: relative;
top: 0px">
<Columns>
<asp:BoundField DataField="ItemID" Visible="false"/>
<asp:BoundField DataField="Name" />
<asp:BoundField DataField="RelDate" />
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Price" />
<asp:BoundField DataField="Status" />
</Columns>
</asp:GridView>