So i have the following method
protected void isDirector_CheckedChanged(object sender, EventArgs e)
{
HtmlTableRow row = (HtmlTableRow)e.Item.FindControl("today");
But getting error
CS0117: 'System.EventArgs' does not contain a definition for 'Item'
EDIT :
<asp:UpdatePanel ID="UpdatePanel2"
runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<asp:RadioButtonList ID="isDirector" RepeatDirection="Horizontal" runat="server" AutoPostBack="True" OnSelectedIndexChanged="isDirector_CheckedChanged">
<asp:ListItem Text="Yes" Value="True" selected></asp:ListItem>
<asp:ListItem Text="No" Value="False"></asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel
<ContentTemplate>
<tr runat="server" id="test">
<td>Director First Name:</td>
<td><asp:TextBox ID="DirectorfirstNametxt" runat="server" MaxLength="100" CssClass="input"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" Display="None" runat="server"
ErrorMessage="Director First Name is required." ControlToValidate="DirectorfirstNametxt"></asp:RequiredFieldValidator>
</td>
</tr>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="isDirector" EventName="SelectedIndexChanged" />
</Triggers>
I am trying to change the CSS CLASS of TR ID = "test"
Assuming you have your Checkboxes inside of a HTML-TableRow and you want to set the CSS-Class of the TR in the CheckedChanged-Event:
This is an example(note that the TR's have a runat="server"-tag):
<table>
<tr ID="TR1" runat="server">
<td>
<asp:CheckBox ID="CheckBox1" OnCheckedChanged="isDirector_CheckedChanged" AutoPostBack="true" runat="server" />
</td>
</tr>
<tr ID="TR2" runat="server">
<td>
<asp:CheckBox ID="CheckBox2" OnCheckedChanged="isDirector_CheckedChanged" AutoPostBack="true" runat="server" />
</td>
</tr>
<tr ID="test" runat="server">
<td>
<asp:CheckBox ID="CheckBox3" OnCheckedChanged="isDirector_CheckedChanged" AutoPostBack="true" runat="server" />
</td>
</tr>
</table>
and this is the codebehind:
protected void isDirector_CheckedChanged(object sender, EventArgs e)
{
//var row = (HtmlTableRow)((CheckBox)sender).Parent.Parent;
test.Attributes("class") = "CssClass";
}
Edit: if your tr's are runat="server" and they have unique ID's, you can access them directly
What kind of control is isDirector_CheckChanged tied to - a checkbox?
As the error says, EventArgs is the type of event you're expecting and it doesn't have an 'Item' property. Maybe you're thinking of GridView, Repeater, or other 'item-like' controls?
I'm guessing you're trying to handle the changed event of a checkbox you've put in a repeating/table control. If so, you'll need to handle a Selected or similar event for the repeater that DOES use an EventArgs-derived type with an Item property.
Related
We have a page that allows users to update data using about a dozen textboxes and several dropdowns. Half of all the fields are permanently visible and the rest are hidden. If a checkbox is checked, the page reveals the rest of the fields.
When first arriving on the page, the two textboxes and dropdown in question are not visible, along with the rest of the fields not visible, unless the checkbox is checked.
However, with the update functionality (a button click) the two textboxes and dropdown appear with the other permanently visible fields. Oddly enough, the labels corresponding to the fields that should be hidden do not appear. Another point is that, if the checkbox is checked and then unchecked, the fields in question are not visible.
So it appears that the issue is with the update functionality but we haven't been able to pinpoint what the issue is. We have tried setting the visibility to false in the .ascx.cs file but that has had zero effect along with other things we've tried.
Is there anything obvious we might be missing from our code below?
ascx:
<asp:FormView ID="FormView1" runat="server" DataSourceID="odsQWER" DataKeyNames="Oid"
OnItemInserting="FormView1_ItemInserting" EnableModelValidation="true"
OnItemUpdating="FormView1_ItemUpdating">
...
<tr>
<td style="width: 200px">
<asp:Label ID="ContactFNameLabel" runat="server" Text="Vendor Contact (First Name):"
Visible="false"></asp:Label>
</td>
<td>
<asp:TextBox Width="400px" ID="ContactFNameTextBox" runat="server" Text='<%# Bind("FirstName") %>'
Visible="false"></asp:TextBox>
<asp:RequiredFieldValidator ID="ContactFNameValidator" runat="server" ControlToValidate="ContactFNameTextBox"
Display="Dynamic" ErrorMessage="Contact Name cannot be Blank" Visible="false"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td style="width: 200px">
<asp:Label ID="ContactLNameLabel" runat="server" Text="Vendor Contact (Last Name):"
Visible="false"></asp:Label>
</td>
<td>
<asp:TextBox Width="400px" ID="ContactLNameTextBox" runat="server" Text='<%# Bind("LastName") %>'
Visible="false"></asp:TextBox>
<asp:RequiredFieldValidator ID="ContactLNameValidator" runat="server" ControlToValidate="ContactLNameTextBox"
Display="Dynamic" ErrorMessage="Contact Last Name cannot be Blank" Visible="false"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td style="width: 200px">
<asp:Label ID="CountryLabel" runat="server" Text="Country:" Visible="false"></asp:Label>
</td>
<td>
<asp:DropDownList Width="405px" ID="CountryDropDownList" runat="server" AppendDataBoundItems="true"
DataSourceID="odsCountry" DataTextField="Name" DataValueField="Oid" SelectedValue='<%# Bind("CountryId") %>'
Visible="false">
<asp:ListItem Selected="true" Text="<--Select Here-->" Value="0"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="CountryValidator" runat="server" ControlToValidate="CountryDropDownList"
Display="Dynamic" ErrorMessage="Country Must be Selected" InitialValue="0"></asp:RequiredFieldValidator>
</td>
</tr>
...
<asp:Button ID="UpdateButton" runat="server" CausesValidation="true" CommandName="Update" OnClick="btnUpdateClick"
CssClass="button" Text="Update" Visible='<%# true %>' />
...
<asp:ObjectDataSource ID="odsQWER" runat="server" InsertMethod="AddRequest"
TypeName="BLL.TESTRequest" SelectMethod="GetRequest" OnInserting="odsQWER_Inserting"
UpdateMethod="UpdateRequest" OnUpdating="odsQWER_Updating" OnInserted="odsQWER_Inserted"
OnUpdated="odsQWER_Updated" OldValuesParameterFormatString="{0}">
...
aspx:
protected void btnUpdateClick(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)FormView1.FindControl("IsNewCheckBox");
FormView1.FindControl("ContactFNameTextBox").Visible = chk.Checked;
FormView1.FindControl("ContactFNameLabel").Visible = chk.Checked;
FormView1.FindControl("ContactFNameValidator").Visible = chk.Checked;
FormView1.FindControl("ContactLNameTextBox").Visible = chk.Checked;
FormView1.FindControl("ContactLNameLabel").Visible = chk.Checked;
FormView1.FindControl("ContactLNameValidator").Visible = chk.Checked;
FormView1.FindControl("StateDropDownList").Visible = chk.Checked;
FormView1.FindControl("StateLabel").Visible = chk.Checked;
}
I have created an aspx page in which I want some controls to be enabled on basis of user selection.
If user selects All two radio buttons should be enabled, hide otherwise.
My declarative part is:
<tr>
<td>
<asp:Label ID="lblCommunityMembers" runat="server" Text="Community Members" />
</td>
<td>
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>
<asp:UpdatePanel ID="upCommunityMembers" runat="server">
<ContentTemplate>
<asp:RadioButton ID="rdbCommunityMembersAll" runat="server" Text="All" GroupName="grpCommMembers" Checked="true" OnCheckedChanged="rdbCommunityMembersAll_CheckedChanged" AutoPostBack="true" />
<asp:RadioButton ID="rdbCommunityMembersSelectedUsers" runat="server" Text="Selected Users" GroupName="grpCommMembers" OnCheckedChanged="rdbCommunityMembersSelectedUsers_CheckedChanged" AutoPostBack="true" />
<SharePoint:ClientPeoplePicker ID="ppCommunityMembers" runat="server" AllowMultipleEntities="true" AllowEmpty="false" Visible="false" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblCommunityCatagory" runat="server" Text="Community Catagory" />
</td>
<td>
<asp:DropDownList ID="ddlCommunityCatagory" runat="server">
<asp:ListItem Value="0">---- Select One ----</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvCommunityCatagory" runat="server" InitialValue="0" ErrorMessage="Please Select Community Catagory"
ForeColor="Red" ControlToValidate="ddlCommunityCatagory" Display="Dynamic" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblCommunityAccess" runat="server" Text="Required Approval?" Visible="false" />
</td>
<td>
<asp:RadioButton ID="rdbRequiredApprovalYes" runat="server" Text="Yes" GroupName="grpCommMembers" Checked="true" Visible="false" />
<asp:RadioButton ID="rdbRequiredApprovalNo" runat="server" Text="No" GroupName="grpCommMembers" Visible="false"/>
</td>
</tr>
My code behind:
protected void rdbCommunityMembersSelectedUsers_CheckedChanged(object sender, EventArgs e)
{
if (rdbCommunityMembersSelectedUsers.Checked)
{
enableControls();
}
else
{
disableControls();
}
}
protected void rdbCommunityMembersAll_CheckedChanged(object sender, EventArgs e)
{
if (rdbCommunityMembersAll.Checked)
{
disableControls();
}
else
{
enableControls();
}
}
protected void enableControls()
{
ppCommunityMembers.Visible = true;
lblCommunityAccess.Visible = true;
rdbRequiredApprovalNo.Visible = true;
rdbRequiredApprovalYes.Visible = true;
}
protected void disableControls()
{
ppCommunityMembers.Visible = false;
lblCommunityAccess.Visible = false;
rdbRequiredApprovalNo.Visible = false;
rdbRequiredApprovalYes.Visible = false;
}
If Community members are selected to all then "Required Approval?" part should get hidden.
But problem is when I select selected users then I am getting only people picker control visible, the required approval contorls are not getting displayed. What am I missing?
Your Radio Buttons rdbCommunityMembersAll and rdbCommunityMembersSelectedUsers are inside update panel, thus they are doing partial postback. To make the control visible outside the UpdatePanel you can do any one of the following:
Move rdbCommunityMembersAll and rdbCommunityMembersSelectedUsers
outside the UpdatePanel
Move the controls you need to make visible
(lblCommunityAccess, rdbRequiredApprovalNo, rdbRequiredApprovalYes)
inside UpdatePanel
Or
Instead of setting Visible="false", set style="display:none" and
trigger the visibility through javascript/jquery
I have the following code.
What i want is when the ddlProvince dropdown is changed, to throw the event SelectedIndexChanged, however that method is never accessed.
<asp:UpdatePanel ID="pnlCountries" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlProvince" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<tr>
<td><asp:Literal ID="Literal37" Text="<%$Resources:glossary,country %>" runat="server"/></td>
<td>
<asp:DropDownList ID="ddlCountries" CssClass="textbox" runat="server">
</asp:DropDownList>
<br />
<cc1:cascadingdropdown ID="cddCountries" runat="server" Category="Country" Enabled="True" LoadingText="<%$Resources:Glossary,loading %>" PromptText="<%$Resources:Glossary,country_choose %>"
ServiceMethod="GetCountries" TargetControlID="ddlCountries">
</cc1:cascadingdropdown>
<asp:RequiredFieldValidator CssClass="errortext" Text="<%$Resources:Glossary,required %>" SetFocusOnError="true" ID="rfvcboScenario" runat="server" InitialValue="" ControlToValidate="ddlCountries" Display="Dynamic" />
</td>
</tr>
<tr>
<td><strong><asp:Literal ID="Literal9" Text="<%$Resources:Glossary,province %>" runat="server" /> *</strong></td>
<td>
<asp:DropDownList ID="ddlProvince" CssClass="textbox" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator CssClass="errortext" Text="<%$Resources:Glossary,required %>" SetFocusOnError="true" ID="RequiredFieldValidator1" runat="server" InitialValue="" ControlToValidate="ddlProvince" Display="Dynamic" />
<cc1:CascadingDropDown ID="cddProvince" runat="server" TargetControlID="ddlProvince" ParentControlID="ddlCountries"
Category="Province" LoadingText="<%$Resources:Glossary,loading %>" prompttext="<%$Resources:Glossary,province_select %>" ServiceMethod="GetProvincesForCountry" >
</cc1:CascadingDropDown>
</td>
</tr>
</ContentTemplate>
</asp:UpdatePanel>
Currently this codeline is never hit:
Protected Sub ddlProvince_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlProvince.SelectedIndexChanged
ReportError("ddlProvince_SelectedIndexChanged", "")
End Sub
update:
previously I had the Autopostback="true" attribute on the ddlProvince control, however, that caused a full postback (issue also described here: Drop Down List (in Update Panel) causing FULL PostBack!)
What am I missing?
EDIT:
You need to set AutoPostBack="true" for the dropdownlist. Change this:
<asp:DropDownList ID="ddlProvince" CssClass="textbox" runat="server">
</asp:DropDownList>
to this:
<asp:DropDownList ID="ddlProvince" CssClass="textbox" runat="server" AutoPostBack="true" >
</asp:DropDownList>
Possibly you haven't set the OnSelectedIndexChanged event in the Markup as seen above.
Three properties you should set: OnSelectedIndexChanged, AutoPostback & EnableViewState
<asp:DropDownList ID="ddlProvince" runat="server"
AutoPostBack="true" EnableViewState="true"
OnSelectedIndexChanged="ddlProvince_SelectedIndexChanged">
</asp:DropDownList>
Incase you are binding your dropdownlist in page_Load event, place it inside !IsPostback condition check:
protected void page_Load ( object sender, EventArgs e )
{
if(!IsPostBack)
{
//DropDownList data bind and all...
}
}
This is my setup: I've got a dropdownlist of people and a linkbutton next to it to add a person. the linkbutton makes an update panel appear. When clicking save, I want the data to be saved and the new person be selected in the dropdown. As far as I can tell, I have done this properly. After I save the data I refresh the dropdownlist and take the new person's value and set it as the selected value. When stepping through, it shows the ddl with the new person and the new person selected! BUT, when the page comes back, the ddl is unchanged, ie NOT refreshed. I thought it might be something with the Update Panel but I got a similar setup to work on another page! It also works on a nested Update Panel (not shown in the following code). Can you think of why this "deception" is happening?
Here is some of my code. Sorry it's so long. Thanks for your help!!
public void AddRequestor_Click(object sender, ImageClickEventArgs e)
{
pnlNewRequestor.Style.Add("display", "none"); //regular panel
ibSubmitTask.Enabled = true;
ibSubmitTaskCancel.Enabled = true;
if (!((ImageButton)sender).ID.Contains("Cancel"))
{
SaveRequestor();
Functions.BindList(ddlRequestors, "Requestor", "spGetRequestors", true);
string newRequestor = txtRequestorLastName.Text + ", " + txtRequestorFirstName.Text;
ddlRequestors.ClearSelection();
ddlRequestors.Items.FindByText(newRequestor).Selected = true;
}
//ASPX Code
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="ddlRequestors" InitialValue=""
ErrorMessage="*Required" CssClass="ErrorText" ValidationGroup="valNewTask" Display="Dynamic" runat="server" />
<asp:LinkButton ID="LinkButton1" Text="Add New Requestor" CssClass="SmallerText" OnClientClick="NoPopup();" OnClick="NewRequestor_Click" runat="server"></asp:LinkButton>
</td>
</tr>
<!-- Add New Requestor Update Panel -->
<tr id="tr1" class="HideXXX" runat="server">
<td></td>
<td colspan="2" class="LeftPadding">
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" CssClass="AddNewPanel Hide" runat="server">
<table width="100%">
<tr>
<td class="SectionTitle" colspan="3"><asp:Label ID="Label1" Text="Add New Requestor" runat="server"></asp:Label>
<hr class="hrSectionTitle" />
</td>
</tr>
<tr id="tr2" class="Hide" runat="server">
<td></td>
<td class="LeftPadding"><asp:Label ID="Label2" CssClass="ErrorTextLarge" runat="server"></asp:Label></td>
</tr>
<tr>
<td><asp:Label ID="Label3" Text="First Name:" runat="server"></asp:Label> </td>
<td><asp:TextBox ID="TextBox1" CssClass="TextBox DefaultFont" OnFocus="this.className='TextBoxFocus DefaultFont'" onBlur="this.className='TextBox DefaultFont'" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtRequestorFirstName"
ErrorMessage="*Required" CssClass="ErrorText" ValidationGroup="valNewRequestor" Display="Dynamic" runat="server" />
</td>
</tr>
<tr>
<td><asp:Label ID="Label4" Text="Last Name:" runat="server"></asp:Label> </td>
<td><asp:TextBox ID="TextBox2" CssClass="TextBox DefaultFont" OnFocus="this.className='TextBoxFocus DefaultFont'" onBlur="this.className='TextBox DefaultFont'" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="txtRequestorLastName"
ErrorMessage="*Required" CssClass="ErrorText" ValidationGroup="valNewRequestor" Display="Dynamic" runat="server" />
</td>
</tr>
<tr>
<td></td>
<td colspan="2">
<asp:ImageButton ID="ImageButton1" ImageUrl="~/Images/Button-AddRequestor.jpg" CausesValidation="true" ValidationGroup="valNewRequestor" OnClientClick="NoPopup();" OnClick="AddRequestor_Click" runat="server" />
<asp:ImageButton ID="ImageButton2" ImageUrl="~/Images/Button-Cancel-Darker.jpg" CausesValidation="false" OnClientClick="NoPopup();" OnClick="AddRequestor_Click" runat="server" />
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lbNewRequestor" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="ibAddRequestor" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="ibAddRequestorCancel" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
I had a similar isssue. Fixed it by mannually adding the new listitem to the dropdown instead of rebinding it ...
I am working with the listview control. By default I am showing the itemtemplate with an edit button. When the edit button is pressed the listview switches to the edititemtemplate. I need to populate one of the controls in the edititemtemplate based on the item being edited - I've tried accessing the control (via FindControl) in the ItemEditing event (and pretty much every other event as well), however the controls just don't seem to exist. I can access controls in the itemtemplate ok, but not the edititemtemplate.
Can anyone let me know how I can access a control held within the edititemtemplate of a listview, and from which event I should do so?
EDIT
I'm trying to access the control using this:
protected void UnitsLV_ItemEditing(object sender, ListViewEditEventArgs e)
{
ListViewItem item = UnitsLV.Items[e.NewEditIndex];
ListBox tempLB = (ListBox)e.item.FindControl("ListBox3");
}
I've also tried in ItemDataBound and ItemCreated.
The listview declaration is:
<asp:Content ID="Content1" ContentPlaceHolderID="ColumnA" runat="server">
<asp:Panel ID="Panel1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="SummaryPnl" runat="server">
<asp:ListView ID="UnitsLV" runat="server" DataSourceID="DataLDS" DataKeyNames="u_uid"
InsertItemPosition="LastItem" OnItemInserting="UnitsLV_ItemInserting" OnItemDataBound="UnitsLV_ItemDataBound"
OnItemCreated="UnitsLV_ItemCreated" onitemediting="UnitsLV_ItemEditing">
<ItemTemplate>
<tr class="rowA">
<td>
<asp:Label runat="server" ID="UnitIDLbl" Text='<%# Eval("u_uid")%>'></asp:Label>
</td>
<td>
<%# Eval("u_Title")%>
</td>
<td>
<asp:LinkButton ID="EditBtn" runat="server" CommandName="Edit" CommandArgument='<%#Eval("u_uid") %>'
Text="Edit" />
</td>
<td>
<asp:LinkButton ID="DeleteBtn" runat="server" CommandName="Delete" CommandArgument='<%#Eval("u_uid") %>'
Text="Delete" />
</td>
</tr>
</ItemTemplate>
<InsertItemTemplate>
<tr class="rowB">
<td>
<br />
</td>
<td>
<br />
<asp:TextBox ID="TitleTB" runat="server" Text='<% #Bind("u_Title")%>'></asp:TextBox>
</td>
<td>
<br />
<asp:ListBox ID="ListBox3" runat="server"></asp:ListBox>
<asp:ListBox ID="ToBeDeletedLB" runat="server"></asp:ListBox>
</td>
<td>
<asp:LinkButton ID="InsertBtn" runat="server" CommandName="Insert" Text="Insert" />
</td>
<td>
<asp:LinkButton ID="CancelBtn" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
</tr>
</InsertItemTemplate>
<EditItemTemplate>
<tr class="rowB">
<td>
<br />
<asp:Label runat="server" ID="UnitIDLbl" Text='<%# Bind("u_uid")%>'></asp:Label>
</td>
<td>
<br />
<asp:TextBox ID="TitleTB" runat="server" Text='<% #Bind("u_Title")%>'></asp:TextBox>
</td>
<td>
<br />
<asp:ListBox ID="ListBox3" runat="server"></asp:ListBox>
<asp:ListBox ID="ToBeDeletedLB" runat="server"></asp:ListBox>
</td>
<td>
<asp:LinkButton ID="UpdateBtn" runat="server" CommandName="Update" Text="Update" />
</td>
<td>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
</tr>
</EditItemTemplate>
<LayoutTemplate>
<table id="Table2" runat="server" width="100%">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="" width="100%">
<tr id="itemPlaceholder" runat="server"></tr>
</table>
</td>
</tr>
<tr id="Tr2" runat="server">
<td id="Td2" runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</asp:Content>
EDIT:
I've iterated over all the controls in the listview using code similar to below, and the control is still not visible. Does the ItemEditing event fire before the edit template is shown? If so, what event can I use to access the edit template controls?
foreach (Control child in control.Controls)
{
Control result = Find(child, id);
if (result != null)
{
return result;
}
}
**EDIT: **
I can access the controls in the edititemtemplate in the listview's ItemCreated event, however none they have no content (I'd assume the data hasn't been bound yet), so I can't get the key-value I need to do a lookup to get the data I need to populate the control.
I've figured out a way to do what I need to do, though I'm not terribly happy with it.
protected void UnitsLV_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (UnitsLV.EditIndex > -1)
{
// Controls within the edititemtemplate are available via e.Item.FindControl("controlname")
}
}
I don't know about previous editions but in Visual Studio 2010 you can easily access the edit item trhough the "ListView.EditItem" property like this:
private void myListView_ItemEditing(object sender, ListViewEditEventArgs e)
{
myListView.EditIndex = e.NewEditIndex;
myListView.DataBind();
ListViewItem lvwItem = lvwLista.EditItem;
ListBox tempLB = (ListBox) lvwItem.FindControl("ListBox3");
}
protected void ListView1_ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
ListBox myListBox = (ListBox)(((ListView)sender).EditItem.FindControl("ListBox1"));
}
protected void UnitsLV_ItemEditing(object sender, ListViewEditEventArgs e)
{
ListViewItem item = UnitsLV.Items[e.NewEditIndex];
ListBox tempLB = (ListBox)e.item.FindControl("ListBox3");
}
I believe I found a typo in the above function. The second line should be
ListBox tempLB = (ListBox)item.FindControl("ListBox3");
What I did was replace "e.item" with "item"
I usually use the ItemDataBound Event... check the other options in ListItemType Enum
protected void UnitLV_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.EditItem)
{
ListBox myListBox = (ListBox) e.Item.FindControl("ListBox3");
}
}
this is similar to the accepted answer, but I think its author was really driving towards this:
protected void UnitsLV_ItemDataBound(object sender, ListViewItemEventArgs e)
{
ListViewDataItem listViewDataItem = e.Item as ListViewDataItem;
if (UnitsLV.EditIndex == listViewDataItem.DataItemIndex)
{
// Controls within the edititemtemplate are available via e.Item.FindControl("controlname")
}
}