srinivas n

srinivas n

  • NA
  • 5
  • 6.8k

How to remove a row in gridview based on session variable

Feb 18 2012 11:29 AM
hello sir,i binded a page gridview(gridproducts) session values to new page gridview(gridcart).(plz evaluate the below aspx code for your clarity).for suppose 2 items are added to the gridcart(gridview) from prev gridview(not mentioned in below code).i added a button next to it(remove).now my intention is to remove that particular item from the gridview.and it should display only 1 item.and i'm not altering any data values in table with sql commands.all the data stored in session temporarily.now i'm trying to make changes for it.and also facing problems with session null value exception how can i overcome this.and 1 more question is .. how to display gridview with empty table.
thanks in adv.

<asp:GridView ID="gridcart" runat="server" AllowPaging="true"
        AutoGenerateColumns="False" Width="754px" Height="265px"
        BackColor="#FFCC99" BorderColor="#CC0000" BorderStyle="Groove"
        BorderWidth="10px" CellPadding="0" Font-Names="Times New Roman"
        ForeColor="Black" HorizontalAlign="Left">
        <Columns>
<asp:TemplateField HeaderText="Model No" ItemStyle-HorizontalAlign="Center" >
<ItemTemplate><asp:Label ID="lbl123" runat="server" Text='<%#Eval("MODELNO")%>'/></ItemTemplate>

<HeaderStyle Height="5px"></HeaderStyle>
<ItemStyle Height="2px"/>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Company" ItemStyle-HorizontalAlign="Center" >
<ItemTemplate><%#Eval("COMPANY")%></ItemTemplate>

<HeaderStyle Height="5px"></HeaderStyle>
<ItemStyle Height="2px"/>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Price" ItemStyle-HorizontalAlign="Center" >
<ItemTemplate><asp:Label ID="lblprice" runat="server" Text='<%#Eval("PRICE")%>'/></ItemTemplate>

<HeaderStyle Height="5px"></HeaderStyle>
<ItemStyle Height="2px"/>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Stock" ItemStyle-HorizontalAlign="Center" >
<ItemTemplate><%#Eval("PIECE")%></ItemTemplate>

<HeaderStyle Height="5px"></HeaderStyle>
<ItemStyle Height="2px"/>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity" ItemStyle-HorizontalAlign="Center" >
<ItemTemplate><asp:TextBox ID="textquan"  Height="20px" Width="40px" MaxLength="3" runat="server"  AutoPostBack="false" OnTextChanged="text"/></ItemTemplate>

<HeaderStyle Height="5px"></HeaderStyle>
<ItemStyle Height="2px"/>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="TotalPrice" ItemStyle-HorizontalAlign="Center" >
<ItemTemplate>
<asp:Label ID="lbltp"  runat="server"/>
</ItemTemplate>

<HeaderStyle Height="5px"></HeaderStyle>
<ItemStyle Height="2px"/>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate><asp:Button ID="btnrem" runat="server" Text="Remove" OnClick="click"/></ItemTemplate>
</asp:TemplateField>
</Columns>
        <HeaderStyle BackColor="Red" BorderStyle="None" ForeColor="#FFFF66"
            HorizontalAlign="Center" />
        <RowStyle BackColor="#CCFFCC" BorderStyle="None" ForeColor="Black"
            HorizontalAlign="Center" />
</asp:GridView>


Answers (4)