How to pass value between pages using link button? - c#

I want to pass the facility_id between pages. However, the link button in the data list does not work.
May I know why it does not work and how to make it work?
Thank you in advance.
Here is the code from the .aspx file:
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatColumns="2" RepeatDirection="Horizontal" HorizontalAlign="Center" Width="70%" DataKeyField="facility_id" OnItemCommand="DataList1_ItemCommand">
<ItemTemplate>
<asp:Label ID="facility_idLabel" runat="server" Text='<%# Eval("facility_id") %>' Visible="False" />
<table style="width:100%;">
<tr>
<td style="height: 53px; width: 500px; text-align: right;">
<asp:Label ID="Label2" runat="server" CssClass="ClientFacility2ndTitle" Text='<%# Eval("facility_name") %>'></asp:Label>
</td>
<td class="lblLogin" style="height: 53px; width: 220px">
<asp:LinkButton ID="LinkButton1" runat="server" BorderStyle="None" CssClass="Button" CommandName="BookNow">Book Now</asp:LinkButton>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:WebConfigcs %>" SelectCommand="SELECT [facility_id], [facility_name] FROM [facility]"></asp:SqlDataSource>
Meanwhile for the code in aspx.cs:
public partial class ClientFacility : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if(e.CommandName == "BookNow")
{
MessageBox.Show(e.CommandArgument.ToString());
Response.Redirect("EditFacility.aspx?facility_id=" + e.CommandArgument.ToString());
}
}
}

you have a CommandName for the link button, but no commandArugment?
so:
<asp:LinkButton ID="LinkButton1" runat="server"
BorderStyle="None" CssClass="Button"
CommandName="BookNow"
CommandArgument = '<%# Eval("facility_id") %>'
>Book Now</asp:LinkButton>
So to pick up e.CommandArugment, you need to set that in the link button.

Related

OnLoad method DataList item`s control

I am building a website right now using DataLists and I want to ask a question:
When using OnLoad on specific control in DataList item, the DataList has 5 items, but the function is called only 4 times (does what it needs to do but not on the last item)
C# code:
protected void ibDeleteAlbum_Load(object sender, EventArgs e)
{
foreach (DataListItem item in DataList1.Items)
{
ImageButton btnDelAlbum = item.FindControl("ibDeleteAlbum") as ImageButton;
btnDelAlbum.Visible = true;
}
}
HTML code:
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="4" >
<ItemTemplate>
<asp:Label ID="lblAlbumID" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Id") %>' Visible="false"></asp:Label>
<asp:ImageButton ID="ibDeleteAlbum" type="image" runat="server" style="position:absolute; margin-right: 1.4vw; margin-top: 2.4vh;" Visible="false" ImageUrl="~/Images/ic_delete.png" OnClick="ibDeleteAlbum_Click" ToolTip="מחיקה" OnLoad="ibDeleteAlbum_Load" />
<asp:ImageButton ID="ibShowAlbums"
runat="server"
class="album"
ImageUrl='<%# DataBinder.Eval(Container.DataItem, "coverPhoto") %>'
CommandName="album"
CommandArgument='<%#DataBinder.Eval(Container.DataItem, "ID") %>'
OnCommand="ibShowAlbums_Command" />
<div class="albumNameShow" runat="server"><%#DataBinder.Eval(Container.DataItem, "albumName") %></div>
</ItemTemplate>
</asp:DataList>
Thanks ahead!

How to show corresponding value of a calculated field through html query string to another page

I'm working on a shopping cart functionality which allows users to add items to a shopping cart(via a add to cart button.) I have a specials page where members get discounted price for items. i have successfully passed the id(database) and sales price (calculated value) from the specials page to a add to cart page.
I couldnt post images because i dont have reputations so here is what the url looks like:
http://localhost:51231/LegoBits/Shopping/ShoppingCartItem.aspx?Id=1&SalesPrice=0.89
You can see the url is getting the values Id and SalesPrice from another page, but , i'm having trouble showing the salesPrice value in datalist of current page.
here is my code for the shoppingCartItem.aspx
<asp:DataList ID="DataList1" runat="server" HorizontalAlign="Center" DataKeyField="Id" ItemStyle-HorizontalAlign="Left" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Thumbnail", "{0}") %>' />
<asp:Label ID="PictureURLLabel" runat="server" Text='<%# Eval ("Thumbnail") %>' Visible="false"></asp:Label>
<br />
<strong style="text-align: left;">Name: </strong>
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
<br />
<strong style="text-align: left;">Model: </strong>
<asp:Label ID="ModelLabel" runat="server" Text='<%# Eval("Model") %>'></asp:Label>
<br />
<strong style="text-align: left;">Ages: </strong>
<asp:Label ID="AgesLabel" runat="server" Text='<%# Eval("Ages") %>'></asp:Label>
<br />
<strong style="text-align: left;">Price: </strong>
$
<asp:Label ID="PriceLabel" runat="server"></asp:Label>
<br />
<br />
<asp:ImageButton ImageUrl="../Images/AddToCart.jpg" ID="Button1" runat="server" OnClick="Button1_Click" />
</ItemTemplate>
</asp:DataList>
and its code behind:
public partial class Shopping_ShoppingCartItem : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
string salePrice = Request.QueryString["Sales Price"];
string price = Request.QueryString["price"];
if (Roles.IsUserInRole("Member"))
{
((Label)DataList1.Controls[0].FindControl("PriceLabel")).Text = salePrice;
}
else {
((Label)DataList1.Controls[0].FindControl("PriceLabel")).Text = price;
}
}
The priceLabel should show the SalesPrice value passed as querystring from another page. Please help me out. Thanks in advance!!!
Please try with the below code snippet.
ASPX
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" HorizontalAlign="Center" DataKeyField="ID" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
<asp:Label ID="PriceLabel" runat="server"></asp:Label>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
ASPX.CS
protected void Page_Load(object source, System.EventArgs e)
{
dynamic data = new[] {
new { ID = 1, Name ="Name_1"}
};
DataList1.DataSource = data;
DataList1.DataBind();
}
protected void Page_PreRender(object source, System.EventArgs e)
{
string salePrice = Request.QueryString["SalesPrice"];
((Label)DataList1.Controls[0].FindControl("PriceLabel")).Text = salePrice;
}
Update 1
ASPX
<asp:DataList ID="DataList1" runat="server" HorizontalAlign="Center" DataKeyField="ID" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
<asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("SalesPrice") %>' ></asp:Label>
</ItemTemplate>
</asp:DataList>
ASPX.CS
protected void Page_Load(object source, System.EventArgs e)
{
dynamic data = new[] {
new { ID = 1, Name ="Name_1", SalesPrice = 10.00}
};
DataList1.DataSource = data;
DataList1.DataBind();
}
protected void Page_PreRender(object source, System.EventArgs e)
{
if (Request.QueryString["SalesPrice"] != null && !string.IsNullOrEmpty(Request.QueryString["SalesPrice"]))
{
string salePrice = Request.QueryString["SalesPrice"];
((Label)DataList1.Controls[0].FindControl("PriceLabel")).Text = salePrice;
}
}
Let me know if any concern.
Just remove the space.
string salePrice = Request.QueryString["SalesPrice"];

Saving textfield for each item in repeater

It seems I have had a lot of questions today.
What i want to do is save the text for each image.
I'm getting the right text for each picture into the textboxes at the moment.
The code behind:
var car = GarageBLL.LoadCar(Convert.ToInt32(CarId),
Convert.ToInt32(_memberId)); ImageRepeater.DataSource = car.Images;
ImageRepeater.DataBind();
protected void FinalizeNewCar(object sender, EventArgs e) {
Response.Redirect("/amcargarasjen"); }
**Code here for saving each edit into the right ImageId.**
ASP:
<asp:Repeater runat="server" ID="ImageRepeater">
<ItemTemplate>
<table>
<tr>
<td>
<a class="deleteLink" href="#" rel="<%#Eval("ImageId")%>" title="">
<asp:Image runat="server" ImageUrl="/Content/Images/Garage/DeleteButton.png" /></a>
<asp:Image Width="60" Height="45" ID="ImgCar" ImageUrl='<%# String.Format("/garageimages/{0}/{1}.{2}", CarId, Eval("ImageId"), Eval("Extension")) %>' runat="server" />
<asp:TextBox runat="server" Text='<%# Eval("Description") %>' ID="txtText"></asp:TextBox>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
<br />
<asp:Button ID="Button1" runat="server" Text="Fullfør" OnClick="FinalizeNewCar" />
Anyone got any ideas on how to do that?
Modify your Repeater HTML markup like below. Note the addition of a Hidden field to keep the reference of the current image ID.
<asp:Repeater runat="server" ID="ImageRepeater">
<ItemTemplate>
<table>
<tr>
<td>
<a class="deleteLink" href="#" rel="<%#Eval("ImageId")%>" title="">
<asp:Image runat="server" ImageUrl="/Content/Images/Garage/DeleteButton.png" /></a>
<asp:Image Width="60" Height="45" ID="ImgCar" ImageUrl='<%# String.Format("/garageimages/{0}/{1}.{2}", CarId, Eval("ImageId"), Eval("Extension")) %>' runat="server" />
<asp:TextBox runat="server" Text='<%# Eval("Description") %>' ID="txtText"></asp:TextBox>
<asp:HiddenField runat="server" Value='<%# Eval("ImageId") %>' ID="txtImageId"></asp:TextBox>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
<br />
<asp:Button ID="Button1" runat="server" Text="Fullfør" OnClick="FinalizeNewCar" />
CODE FinalizeNewCar Event Handler
protected void FinalizeNewCar(object sender, EventArgs e)
{
foreach (RepeaterItem item in ImageRepeater.Items)
{
Int32 imageId = Convert.ToInt32(((HiddenField) item.FindControl("txtImageId")).Value);
string description = ((TextBox)item.FindControl("txtText")).Text;
//You will get the imageId description here.
//Write your code to update the datatbase.
}
}

div tag visible attribute is not working

I use web control in asp.net using c#. I use div tag. on btnProviderSubmit1 i change visibility of divprov. but divprov is not visible false. It visible.
pos.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeFile="pos.ascx.cs" Inherits="USerControls_Recharge_pos" %>
<%# Register Assembly="Gaia.WebWidgets" Namespace="Gaia.WebWidgets" TagPrefix="gaia" %>
<form id="Form1" runat="server">
<div>
<div>
<asp:LinkButton runat="server" ID="moveTo" Text="Go To Classical Mode" PostBackUrl="~/DesktopModules/Recharge/Recharge.aspx" OnClick="SaveCookies"/>
</div>
<div title="Select Provider" id="divprov" **visible="true"** runat="server" style="border-width:medium;border-color:Blue;border-width:medium;">
<asp:ListView DataSourceID="ObjectDataSource1" GroupItemCount="12" GroupPlaceholderID="groupPlaceholder" ItemPlaceholderID="itemPlaceholder" ID="ddlprovider" runat="server">
<LayoutTemplate >
<table runat="server" id="table2" style="border-width:medium" cellpadding="3">
<tr runat="server" id="groupPlaceholder">
</tr>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr runat="server" id="productRow" style="height:80px">
<td runat="server" id="itemPlaceholder">
</td>
</tr>
</GroupTemplate>
<ItemTemplate>
<td id="Td2" valign="top" align="center" style="width:100" runat="server">
<gaia:ImageButton runat="server" CommandArgument='<%#Eval("providerID") %>' **OnCommand="btnProviderSubmit1"** ImageUrl='<%# getImageURL(Eval("providerCode")) %>' ID="ImageButton1" /><br />
<gaia:LinkButton runat="server" CommandArgument='<%#Eval("providerID") %>' OnCommand="btnProviderSubmit1" Text='<%#Eval("description") %>' ID="lnkButton1"/>
</td>
</ItemTemplate>
</asp:ListView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}" SelectMethod="FetchAll"
TypeName="mogile.MidTier.DAL.ProviderController" UpdateMethod="Update">
</asp:ObjectDataSource>
</div>
<div>
<gaia:Panel runat="server" ID="pnlCircle" Visible="false" ScrollBars="Auto">
<asp:ListView ID="ddlCircle" GroupItemCount="8" GroupPlaceholderID="groupPlaceholder" ItemPlaceholderID="itemPlaceholder" runat="server" DataSourceID="ObjectDataSource2">
<LayoutTemplate>
<table runat="server" id="table2" cellpadding="3">
<tr runat="server" id="groupPlaceholder">
</tr>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr runat="server" id="tableRow">
<td runat="server" id="itemPlaceholder" />
</tr>
</GroupTemplate>
<ItemTemplate>
<td id="Td1" runat="server">
<gaia:LinkButton ID="LinkButton1" OnCommand="btnCircleSubmit" Font-Size="Larger" BorderColor="red" BorderWidth="4px" runat="server" CommandArgument='<%#Eval("StateID") %>' Text='<%#Eval("StateName") %>'/>
</td>
</ItemTemplate>
</asp:ListView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}" SelectMethod="FetchAll"
TypeName="mogile.MidTier.DAL.StateController" UpdateMethod="Update">
</asp:ObjectDataSource>
</gaia:Panel>
</div>
</div></form>
pos.ascx.cs
public partial class USerControls_Recharge_pos : System.Web.UI.UserControl
{
private static int itemid = 0;
private static string circleCode;
private static string pdfText;
private static string providerName;
private static string productGrp;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnProviderSubmit1(object sender, CommandEventArgs e)
{
providerName = e.CommandArgument.ToString();
loadProductGroups(e.CommandArgument.ToString());
pnlCircle.Visible = true;
**divprov.Visible = false;**
}
protected void btnCircleSubmit(object sender, CommandEventArgs e)
{
circleCode = e.CommandArgument.ToString();
pnlProductGrp.Visible = true;
// pnlCircle.ForceAnUpdate();
}
}
A workaround could probably be to add "display:none" (or was it "visibility:hidden"? - you can google here) to the style attribute programatically in the btnClick handler.

How to Edit data in nested Listview

I am using listview to display a list of items and a nested listview to show list of features to each item. Both parent and child listview need to able Insert,Edit and delete operation. It works fine for parent listview. But when I try to edit an child item, The edit button does not take it into Edit mode. Can you please suggest me what I am missing in my code?
<asp:ListView ID="lvParent" runat="server"
OnItemDataBound="lvParent_ItemDataBound"
onitemcanceling="lvParent_ItemCanceling" onitemcommand="lvParent_ItemCommand"
DataKeyNames="ItemID" onitemdeleting="lvParent_ItemDeleting"
oniteminserting="lvParent_ItemInserting" >
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
<div align="right">
<asp:Button ID="btnInsert" runat="server" Text="ADD Item" onclick="btnInsert_Click"/>
</div>
</LayoutTemplate>
<ItemTemplate>
<table runat="server" cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td>
<div id="dvDetail">
<span >Description</span>
<asp:TextBox ID="txtDescription" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>' TextMode="MultiLine" ></asp:TextBox>
</div>
<div id="dvFeature" >
<span>Feature List</span>
<asp:ListView ID="lvChild" runat="server"
InsertItemPosition="LastItem"
DataKeyNames="FeatureID" OnItemCommand="lvChild_ItemCommand"
OnItemCanceling="lvChild_ItemCanceling" OnItemDeleting="lvChild_ItemDeleting"
OnItemEditing="lvChild_ItemEditing" OnItemInserting="lvChild_ItemInserting" OnItemUpdating="lvChild_ItemUpdating"
DataSource='<%# DataBinder.Eval(Container.DataItem, "FeatureList") %>' >
<LayoutTemplate>
<ul >
<asp:PlaceHolder runat="server" ID="itemPlaceHolder" ></asp:PlaceHolder>
</ul>
</LayoutTemplate>
<ItemTemplate>
<li>
<span class="dvList"><%# DataBinder.Eval(Container.DataItem, "FeatureTitle")%></span>
<div class="dvButton" >
<asp:ImageButton ID="btnEdit" runat="server" ImageUrl="/Images/edit_16x16.gif" AlternateText= "Edit" CommandName="Edit" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "FeatureID") %>' Width="12" Height="12" />
<asp:ImageButton ID="btnDelete" runat="server" ImageUrl="/Images/delete_16x16.gif" AlternateText= "Delete" CommandName="Delete" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "FeatureID") %>' Width="12" Height="12" />
</div>
</li>
</ItemTemplate>
<EditItemTemplate>
<li>
<asp:TextBox ID="txtFeature" Text='<%# DataBinder.Eval(Container.DataItem, "FeatureTitle")%>' runat="server"></asp:TextBox>
<div class="dvButton">
<asp:ImageButton ID="btnUpdate" runat="server" ImageUrl="/Images/ok_16x16.gif" AlternateText= "Update" CommandName="Update" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "FeatureID") %>' Width="12" Height="12" />
<asp:ImageButton ID="btnCancel" runat="server" ImageUrl="/Images/delete_16x16.gif" AlternateText= "Cancel" CommandName="Cancel" Width="12" Height="12" CausesValidation="false" />
</div>
</li>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txtFeature" runat="server"></asp:TextBox>
<div class="dvButton">
<asp:ImageButton ID="btnInsert" runat="server" ImageUrl="/Images/ok_16x16.gif" AlternateText= "Insert" CommandName="Insert" Width="12" Height="12" />
<asp:ImageButton ID="btnCancel" runat="server" ImageUrl="/Images/delete_16x16.gif" AlternateText= "Cancel" CommandName="Cancel" Width="12" Height="12" CausesValidation="false" />
</div>
</InsertItemTemplate>
</asp:ListView>
</div>
</td>
</tr>
<tr>
<td align="right">
<div id="dvButton" >
<asp:Button ID="btnSave" runat="server" Text="Save"
CommandName="Save"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ItemID") %>' />
<asp:Button ID="btnDelete" runat="server" Text="Delete" CssClass="Cancel"
CommandName="Delete"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ItemID") %>' />
</div>
</td>
</tr>
</table>
</ItemTemplate>
</asp:ListView>
Code Behind:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
BindData();
}
}
private void BindData()
{
MyDataContext data = new MyDataContext();
var result = from itm in data.ItemLists
where itm.ItemID == iItemID
select new
{
itm.ItemID,
itm.Description,
FeatureList = itm.Features
};
lvParent.DataSource = result;
lvParent.DataBind();
}
protected void lvChild_ItemEditing(object sender, ListViewEditEventArgs e)
{
ListView lvChild = sender as ListView;
lvChild.EditIndex = e.NewEditIndex;
lvChild.DataBind();
}
Edit:
protected void lvChild_ItemEditing(object sender, ListViewEditEventArgs e)
{
ListView lvChild = sender as ListView;
lvChild.EditIndex = e.NewEditIndex;
lvChild.DataBind();
}
If I use "lvChild.DataBind()" in 'ItemEditing' event, the total list of child items goes away if I click 'edit'
protected void lvChild_ItemEditing(object sender, ListViewEditEventArgs e)
{
ListView lvChild = sender as ListView;
lvChild.EditIndex = e.NewEditIndex;
}
if I get rid of 'lvChild.Databind' in ItemEditing event, it goes to Edit mode after clicking the 'edit' button twice . And though it shows textbox control of EditItemTemplate, it appears as a blank textbox (does not bind existing value to edit).
This is an interesting problem. Almost certainly a databinding issue. In order to enter edit mode you must do two things:
1) Set the EditIndex
2) Call DataBind()
In the case of nested repeaters though... when does Render get called? I suspect you will have to call DataBind() on the PARENT in order to render everything correctly. That being the case you may have to then set the EditIndex AGAIN, since you are rebinding the parent.
EDIT:
OK... I just tried this with a nested GridView and I did NOT have to DataBind() the parent to get the sub grid to enter edit mode. Now I have to downvote my own answer. :|
hope that will serve someone, somewhere.
Here is my code to get that to work:
1) I have a Listview wich hold a user control when editing. This User cotnrol has itself a listview inside
<asp:ListView runat=server ID=C_LV_MyObjects DataKeyNames="Id"
OnItemDataBound=DataBoundMyObjects OnItemEditing=ItemEditing
>
<LayoutTemplate>
<table runat=server id="itemPlaceholderContainer">
<tr>
<th>
Description
</th>
</tr>
<tr runat="server" id="itemPlaceholder">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
text...
</td>
<td>
<asp:LinkButton runat="server" CommandName="Edit" Text="Edit"></asp:LinkButton>
</td>
<td>
<asp:LinkButton runat="server" CommandName="Delete" Text="Delete"></asp:LinkButton>
</td>
</ItemTemplate>
<EditItemTemplate>
<tr>
<td colspan=3>
<MyTag:MyUC ID=C_UC_MyUserControl runat=server
OnEditing=MyObjectEditing
/>
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
No results found!
</EmptyDataTemplate>
</asp:ListView>
The code c# for this listview is as follows :
public int EditIndexComposition;
protected void ItemEditing(object sender, ListViewEditEventArgs e)
{
C_LV_MyObjects.EditIndex = e.NewEditIndex;
C_LV_MyObjects.DataBind();
}
protected void MyObjectEditing(object sender, EventArgs e)
{
ListViewEditEventArgs MyEvent = (ListViewEditEventArgs)e;
if (MyEvent != null)
EditIndexComposition= MyEvent.NewEditIndex;
C_LV_MyObjects.DataBind();
}
protected void DataBoundMyObjects(object sender, ListViewItemEventArgs e)
{
MyUC uc = (MyUC)e.Item.FindControl("C_UC_MyUserControl");
if (uc!=null)
{
uc.EditIndex = EditIndexComposition;
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
MyObject obj= (MyObject)dataItem.DataItem;
uc.DataSource=Myservice.GetDatasource(obj.Id);
uc.DataBind();
}
}
and the code of my Usercontrol is as follows :
<asp:PlaceHolder runat="server" ID="C_PH_ObjComposition">
<asp:ListView runat="server" ID="C_LV_AppaltatoreComposizione" DataSource="<% # DataSource %>"
DataKeyNames="Id" OnItemEditing="ItemEditing">
etc...
<ItemTemplate>
<tr>
<td>
<asp:LinkButton runat="server" CommandName="Edit" Text="Edit"></asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr>
<td>
Edit Mode
</td>
</tr>
</EditItemTemplate>
</asp:ListView>
</asp:PlaceHolder>
with the following code c# :
public int EditIndex
{
get {return C_LV_ObjComposition.EditIndex;}
set { C_LV_ObjComposition.EditIndex=value;}
}
public event EventHandler Editing;
protected void ItemEditing(object sender, ListViewEditEventArgs e)
{
C_LV_ObjComposition.EditIndex = e.NewEditIndex;
if (Editing != null)
Editing(this, e);
}
When clicking on the edit button of the innerlistview, we store the index that was clicked and we trigger a function in the first container user control. This function is going to store in a global value the index cliked and triggers a databind of the outter list. Doing so we get the onitemdatabound, that will recreate our usercontrol with the proper values, we can then before the databinding of the usercontrol assign the index of the editing row.
That's all if you have any questions , please feel free to answer..
ciao!

Categories

Resources