Hi Friends,
In the default.aspx page
1. Added the Add more button
<asp:ImageButton ID="ImgAddItem" runat="server" Height="30px"
ImageUrl="~/Images/AddItem.png" onclick="ImgAddItem_Click" Width="30px"
EnableViewState="False" />
2.Added the repeater control which contains three controls (dropdown and 2 textboxes )
<asp:repeater id="Repeater1" runat="server" >
<itemtemplate>
<tr>
<td style="padding-removed10px; width:130px;">
<asp:Label ID="lblitems" runat="server" Font-Names="Verdana" Font-Size="Small"
Text="Items" Width="100px">
</td>
<td>
<asp:DropDownList ID="ddlitems" runat="server" AppendDataBoundItems="True"
AutoPostBack="True" CssClass="ddl" Width="145px" DataTextField="ItemsName"
DataValueField="ItemsId" DataSourceID="SDSItems">
<asp:ListItem Selected="True" Value="0">--Select--
<asp:RequiredFieldValidator ID="RFV_cash_sfirm1" runat="server"
ControlToValidate="ddlitems" Display="Dynamic"
ErrorMessage="Please Select Firm" InitialValue="0" SetFocusOnError="True"
ValidationGroup="Submit">*
</td>
<td style="padding-removed10px; width:130px;">
<asp:Label ID="lblQuantity" runat="server" Font-Names="Verdana"
Font-Size="Small" Text="Quantity" Width="100px">
</td>
<td>
<asp:TextBox ID="txtQuantity" runat="server" AutoPostBack="True"
ontextchanged="txtQuantity_TextChanged" Width="140px">
</td>
<td style="padding-removed10px; width:130px;">
<asp:Label ID="lblprice" runat="server" Font-Names="Verdana" Font-Size="Small"
Text="Price" Width="100px">
</td>
<td>
<asp:TextBox ID="txtprice" runat="server" style="text-align:right"
Width="140px">
</td>
<td>
<asp:ImageButton ID="ImgRemoveItem" runat="server"
ImageUrl="~/Images/cancel.gif" onclick="ImgRemoveItem_Click" Visible="True" />
</td>
</tr>
</itemtemplate>
3.When we click on the add button new row will be added ..by using the following code
protected void ImgAddItem_Click(object sender, ImageClickEventArgs e)
{
List<int32> _tmpList = ControlsList;
_tmpList.Add(_tmpList.Count);
ViewState["ControlsList"] = _tmpList;
BindTemplate();
}
private void BindTemplate()
{
Repeater1.DataSource = ControlsList;
Repeater1.DataBind();
}
private List<int32> ControlsList
{
get
{
if (ViewState["ControlsList"] != null)
{
return ViewState["ControlsList"] as List<int32>;
}
else
{
List<int32> _tmpList = new List<int32>();
_tmpList.Add(_tmpList.Count);
ViewState["ControlsList"] = _tmpList;
return _tmpList;
}
}
set
{
ViewState["ControlsList"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindTemplate();
}
}
Its working Fine..But the problem is,
When we entered the data in First Row and clicked on the add more button,The new row is creating successfully at the same time ,we are losing the data from the controls of first row which i have entered before..
Pls help me..Thanks in Advance