my problem is how display selected item and a content of textbox in a gridview after a submit button dynamically (i will repeat more than 1 time) and so automatically the submit button will insert data in DB(entity framework)
the DropDownList1 is populated from db
to explain more this my page :
In order to resolve your issue as soon as posssible, could you explain what is the main issue about your code? Is there any exception is thrown out? If it is, please debug your code step by step and point out where the exception is thrown out . That will
help us continue.
Best wishes,
Please mark the replies as answers if they help or unmark if not.
Feedback to us
Thank you Catherine for your response, in fact i havn't a debug problem but i could not reach my goal for keeping the last inserted line in gridview after a postback.
my issue is when i add a new line in gridview from a selected index changing of drop down list it is displayed in grid but when i try to add more lines the last inserted line disappear so i want to keep it.
I think it is a problem of a viewstate but i don't know how to use it .
samio07
0 Points
2 Posts
problem with dynamic displaying grid view
Aug 03, 2012 02:18 PM|LINK
my problem is how display selected item and a content of textbox in a gridview after a submit button dynamically (i will repeat more than 1 time) and so automatically the submit button will insert data in DB(entity framework)
the DropDownList1 is populated from db
to explain more this my page :
<fieldset id="Item2">
<legend> Item Information</legend>
<br />
<br />
<center>
<table>
<tr>
<td>
<asp:Label ID="lblIemName" runat="server" >Item Name</asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
AppendDataBoundItems="true" EnableViewState="true">
<asp:ListItem Value="0">--Select--</asp:ListItem></asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblQuantity" runat="server" >Quantité</asp:Label>
</td>
my behind code is :
<td>
<asp:TextBox ID="txtQuantity" runat="server" Width="62px"></asp:TextBox></td>
<td><asp:ImageButton ID="btnAddItem" runat="server" Height="20" Width="20" ImageUrl="~/Images/Add.png" OnClick="btnAddItem12_click" />
</td>
</tr>
</table>
</center>
<br />
<br />
<center>
<asp:GridView ID="gvPurchasedItem" runat="server" AutoGenerateColumns="False" DataKeyNames="IDItemLinePurchased"
BackColor="Aquamarine">
<Columns>
<asp:BoundField HeaderText="CategoryName" ControlStyle-Width="250" DataField="CategoryName">
<ControlStyle Width="250px"></ControlStyle>
</asp:BoundField>
<asp:BoundField HeaderText="ItemName" DataField="ItemName" />
<asp:BoundField HeaderText="Quantity" DataField="Quantity" />
</Columns>
</asp:GridView>
</center>
</fieldset>
my behind code is :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Populateddlitem();
}
}
void Populateddlitem()
{
DropDownList1.DataTextField = "ItemName";
DropDownList1.DataValueField = "IDItem";
DropDownList1.DataSource = LogicItem.Instance.GetItems();
DropDownList1.DataBind();
}
protected void btnAddItem_click(object sender, ImageClickEventArgs e)
{
// insert bloc
ItemLinePurchased res = null;
if (ID == 0)
res = new ItemLinePurchased();
else res = LogicItemLinePurchased.Instance.GetItemLinePurchasedByID(ID);
res.Quantity = Convert.ToInt32(txtQuantity10.Text);
res.IDItem = Convert.ToInt32(DropDownList1.SelectedItem.Value);
ViewState["ddl"] = DropDownList1.SelectedItem.Value;
res.IDPurchasesDoc = Convert.ToInt32(ViewState["PurchasesDocid"]);
res.State = "IsActive";
LogicItemLinePurchased.Instance.SaveItemLinePurchased(res);
int aaa = DropDownList1.SelectedIndex;
int bbb = Convert.ToInt32(Session["ddlState"]);
ViewState["id"] = res.IDItemLinePurchased;
//display grid view
gvPurchasedItem.DataSource = (from ItemLinePurchased in LogicItemLinePurchased.Instance.GetAllItemLinePurchased()
where ItemLinePurchased.IDItemLinePurchased == Convert.ToInt32(ViewState["id"]) && ItemLinePurchased.State == "IsActive"
select new
{
ItemLinePurchased.IDItemLinePurchased,
ItemLinePurchased.Item.Category.CategoryName,
ItemLinePurchased.Item.ItemName,
ItemLinePurchased.Quantity,
}).ToList();
gvPurchasedItem.DataBind();
}
any one have a solution to my problem post it and thanks
Catherine Sh...
All-Star
23373 Points
2490 Posts
Microsoft
Re: problem with dynamic displaying grid view
Aug 10, 2012 07:40 AM|LINK
Hi,
In order to resolve your issue as soon as posssible, could you explain what is the main issue about your code? Is there any exception is thrown out? If it is, please debug your code step by step and point out where the exception is thrown out . That will help us continue.
Best wishes,
Feedback to us
Develop and promote your apps in Windows Store
samio07
0 Points
2 Posts
Re: problem with dynamic displaying grid view
Aug 10, 2012 10:25 AM|LINK
Thank you Catherine for your response, in fact i havn't a debug problem but i could not reach my goal for keeping the last inserted line in gridview after a postback.
my issue is when i add a new line in gridview from a selected index changing of drop down list it is displayed in grid but when i try to add more lines the last inserted line disappear so i want to keep it.
I think it is a problem of a viewstate but i don't know how to use it .
could you please help me to resolve it ?