ListView onclick edit row without Edit link problem (GridView worked...)

Hello,

I was initially using a GridView to enable row editing when any element of the row was clicked.  I'm using this control inside an UpdatePanel for partial-page postbacks. 

This was basically accomplished by:

 

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {
//... if (e.Row.RowType == DataControlRowType.DataRow) {
string jsCommand = string.Format("if ({2} != {1}) __doPostBack('{0}','Edit${1}')", GridView1.ID, e.Row.RowIndex, GridView1.EditIndex);
foreach (TableCell c in e.Row.Cells)
{
// OnClick enable the editable cells of each row if (c == e.Row.Cells[0] || c == e.Row.Cells[1])
{
// Add the onclick->GridView edit c.Attributes["onclick"] += jsCommand;

I'm adding to the onclick attribute of the <TD>, which posts back and tells the GridView to go into edit mode.  Well the GridView had some limitations that I wanted to avoid unrelated to this (doesn't show footer on empty datasource, can't have two footer rows (1) for adding a new row and (2) summary information) and the ListView seemed like a good option.  I converted all of my code to use a ListView instead.  The problem is the ListView ignores any postbacks that simply say "Edit", and the only way I was able to get this to work was by including a LinkButton with CommandName="Edit", making it invisible (style="visibility:hidden"), and then duplicating the javascript postback link from the LinkButton when it was visible.  I don't want extra, hidden controls - it's messy.  I may also want to create future events that I want the ListView to react to.

Is there any way to add an onclick event to a ListView table cell so the ListView actually goes into Edit mode, or Update mode for a specific Item/Row? 

Whenever I try the "Edit" like: __doPostBack('ListView1','Edit$0'), the ListView ignores the postback and does not go into edit mode.  I've also tried javascript:__doPostBack('ListView1$ctrl3','') for row 3, but I get no results.  Is there something different that needs to be done for the ListView so I can put it into these Edit/Update modes?

ASP.Net Code from my ListView:

                <ItemTemplate>
<tr id="row" runat="server" class='<%# Container.DataItemIndex % 2 == 0 ? "row" : "altrow" %>'>
<td><asp:Label ID="lblHours1" runat="server" Text='<%# Bind("text") %>'></asp:Label></td>
<td><asp:Label ID="lblHours2" runat="server" Text='<%# Bind("link") %>'></asp:Label><asp:LinkButton ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" style="visibility:hidden" /></td>

</tr>
</ItemTemplate>
<EditItemTemplate>
<tr id="row" runat="server" class='<%# Container.DataItemIndex % 2 == 0 ? "row" : "altrow" %>'>
<td><asp:TextBox ID="txtHours1" runat="server" Text='<%# Bind("text") %>'></asp:TextBox></td>
<td><asp:TextBox ID="txtHours2" runat="server" Text='<%# Bind("link") %>'></asp:TextBox><asp:LinkButton ID="btnUpdate" runat="server" Text="Update" CommandName="Update" /></td>
</tr>
</EditItemTemplate>

 

Any comments or suggestions is greatly appreciated.

Thanks.

 

 

0
skelman
3/11/2009 6:58:28 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
1685 Views

Similar Articles

[PageSpeed] 24
Get it on Google Play
Get it on Apple App Store

Hi skelman ,

skelman:
I've also tried javascript:__doPostBack('ListView1$ctrl3','') for row 3, but I get no results. 

Check my sample ,

        protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            Button btn = e.Item.FindControl("EditButton") as Button;
            if (btn != null)
            {
                string sr = this.ClientScript.GetPostBackClientHyperlink(btn,"");
                Panel p = e.Item.FindControl("p") as Panel;
                p.Attributes.Add("onclick",sr);

                Panel p1 = e.Item.FindControl("p1") as Panel;
                p1.Attributes.Add("onclick", sr);

                Panel p2 = e.Item.FindControl("p2") as Panel;
                p2.Attributes.Add("onclick", sr);

               
            }
        }

 


<asp:ListView ID="ListView1" runat="server" DataKeyNames="id"
        DataSourceID="SqlDataSource1" onitemdatabound="ListView1_ItemDataBound">
 
      
        <LayoutTemplate>
            <table runat="server">
                <tr runat="server">
                    <td runat="server">
                        <table ID="itemPlaceholderContainer" runat="server" border="0" style="">
                            <tr runat="server" style="">
                                <th runat="server">
                                    id</th>
                                <th runat="server">
                                    name</th>
                            </tr>
                            <tr ID="itemPlaceholder" runat="server">
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr runat="server">
                    <td runat="server" style="">
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
    
     
        <EditItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="UpdateButton" runat="server" CommandName="Update"
                        Text="Update" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
                        Text="Cancel" />
                </td>
                <td>
                    <asp:Label ID="idLabel1" runat="server" Text='<%# Eval("id") %>' />
                </td>
                <td>
                    <asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
                </td>
            </tr>
        </EditItemTemplate>
        <ItemTemplate>
            <tr style="">
           
                <td>
                <asp:Panel ID="p" runat="server">
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                    </asp:Panel>
                </td>
                <td>
                <asp:Panel ID="p1" runat="server">
                    <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
                   </asp:Panel>
                </td>
                <td>
                <asp:Panel ID="p2" runat="server">
                    <asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' />
                    </asp:Panel>
                   
                </td>
               
            </tr>
        </ItemTemplate>
    </asp:ListView>

 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
3/16/2009 9:10:39 AM

 Thank you for your response.

I understand what your code is doing, but I am trying to accomplish "Edit mode" for the ListView without a LinkButton or Button that says "Edit" (or CommandName="Edit").  I would like to put the ListView into Edit mode without these controls, only javascript. 

I want the user to click on the row to put that row into edit mode, but I don't want to need to hide a LinkButton/Button control.
 

0
skelman
3/16/2009 4:15:58 PM
Reply:

Similar Artilces:

ListView onclick edit row problem (w/o Edit Link)...GridView worked
Hello,I was initially using a GridView to enable row editing when any element of the row was clicked.  I'm using this control inside an UpdatePanel for partial-page postbacks.  This was basically accomplished by: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {//...if (e.Row.RowType == DataControlRowType.DataRow) { string jsCommand = string.Format("if ({2} != {1}) __doPostBack('{0}','Edit${1}')", GridView1.ID, e.Row.RowIndex, GridView1.EditIndex); foreach (TableCell c in e.Row.Cells) { // OnClick enable the edi...

Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.
Hi all  I have a questions that looks hard / complex to me, and i know you can help me in this. Q {  I have row in a Gridview and i have an edit option to it. I press the edit button, to edit the values in that row and update data all the way back to the database. Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.) } I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in ...

Direct editing of gridView or Ddatagrid controls without clicking on an EDIT link
I have an application where lots of data is presented to the user in a gridView control and the user needs the option to review and overwrite any values in the cells of the grid.  My users find it very annoying and time consuming to click on an edit link to turn a row of the gridView into edit mode.  Typically, they might jump around and edit a few values in several rows.  Is there any way to present the data in a gridView control, datagrid control or something that looks like a grid where the entire grid is already in edit mode?  Can you make a grid that cont...

GridView: editing without clicking edit link
Hi guys, I'd like to edit the content of the gridview without using 'edit' link. User can just click the cell and edit the data. Any links or thoughts would be appreciate.I can do it! Well, I have not tried but take a look at this: http://www.targetprocess.com/blog/2007/10/grid-inline-editing-using-aspnet-ajax.html Other than these, there are 3rd party grids which let you do MS Excel like editing. A Google search will help.Mark replies as answers if they helped you solve the problem. I don't want to pay for the control. Googled, but no luck. Any ideas?I can do it! ...

GridView control enters edit mode only when I click Edit link twice
Hi all..I have a GridView control in an ASP.NET 2.0 page. I added a column that contains edit, update, cancel buttons. Because I did that, I had to handle RowEditing event or an exception was thrown.Well... this is the body of the RowEditing event:protected void gvParametros_RowEditing(object sender, GridViewEditEventArgs e){      gvParametros.EditIndex = e.NewEditIndex;}The fact is that when page is loaded and I click the edit link, page is refreshed but GridView doesn't enter edit mode. When I press edit link again, GridView enters edit mode.Any help to solve this behavior w...

Allow editing of all rows simultaniously (without having to click edit/update for each row)?
I have an application where the user will be presented with perhaps 20 rows.  1 field of each row (the score) will need to be updated by the user.   Now with a gridview they would click on the first row's EDIT button then make the change for the Score field and then click update. Having to do this ~20 times would be somewhat annoying for the user :)  Is there any way I can get an Excel like behavior where the user can just click on the first row's Score field then enter the integer score and hit tab or down arrow or something and drop down to the next one and keep ...

gridview edit problem on edited datatable
my GridView's datasource is SqlDataSource but i need  assign DataTable to SqlDatasource ( for gridviews edit property). like that : datatable dt = new ... sqldatasource1.datasource = dt;   could anyone help me?? t A SqlDataSource is a DataSource itself. You cannot assign a DataSource to it. A SqlDataSource generates a DataSource.Thanks, EdMicrosoft MVP - ASP/ASP.NET...

Is there really an easy way to click and edit a cell value at run time (without having to click on Edit and Update links) in GridView?
 Link for an answer is broken. Anyway I want know just that. RegardsLeif  I'm talking with absolutely no knowledge, but why not to trigger "onblur" event in the client textbox and forward it to whatever the edit-and-update links go?...

Row editing without edit button.
I am using Gridview.  I am edting a row with edit button but I need  edit row directly in grid  without using Edit button. If possible please help me.  ...

How to get the data of a particular row in gridview without editing that row.
I have a gridview in a page in that ihave hyperlink as one column on click of that i want to go next page with the data present in that corresponding row. How shell i read the data from grid view for that pirticular row.On which event i can get the data. HI, the row that is selected should be passed into a string or an array or in sessionsthis can be done through this code  protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)    {        Label _lbl = new Label();      &...

Problem with edit control of gridview
I am having an issue that after I click update the selected row will not return to the EDIT Delete selection, see the 4 row. why is this??       Expected Recoveries   Program Name Total OnHand Inv $'s Total OnHand E&0 Q4 (12/31) Q4 FY (2007) Q1 (03/30) Q1 FY (2008) Q2 (06/29) Q2 FY (2008) Q3 (09/28) Q3 FY (2008) All Reductions After 09/28/2008 E&U Code Program Mgr. Disposition, Resolution comments of OnHand E&O OnOrder Excess OnOrder Obsolete Total OnOrder E&O   Edit Delete 3COM 0 ...

Problem with Row editing in Gridview
Hi Friends,  I am working with VS.net2008 Gridview and i am doing Row editing, updating, deleting manipilations in the gridview.  My problem is, when ever i click on eithor EDIT or UPDATE or DELETE, The respective event is firing 2 times,,.,   Can you any once help in this,.   Thanks in Advance Regards Ravikrishna Ravikrishna:Hi Friends,  I am working with VS.net2008 Gridview and i am doing Row editing, updating, deleting manipilations in the gridview.  My problem is, when ever i click on eithor EDIT or UPDATE or DELETE, The respective event is firi...

Multiline editing problems in DW edit control on Tabpage
Hi, I have a text column in a datawindow that is used for data entry. It behaves like a multiline edit control except that when the user hits the "enter" key the cursor does not move to a new line. Since the entries need to be in paragraph form, this is a problem. Cutting and pasting documents from email or a word processor works just fine. Any ideas on how to get the column to allow carriage returns? TIA, Jim ---== Posted via the PFCGuide Web Newsreader ==--- http://www.pfcguide.com/_newsgroups/group_list.asp checkout KeyDown event. "Jim" <Jeem62@a...

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: http://forums.asp.net/t/1069245.aspx Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

Web resources about - ListView onclick edit row without Edit link problem (GridView worked...) - asp.net.presentation-controls

Optimizing ListView item rendering
For many Windows Store apps written in JavaScript that work with collections, cooperating well with the WinJS ListView control is essential for ...

Improvements to the ListView control in WinJS 2.0
We’re proud to describe the improvements we have made to the ListView control for the Windows Library for JavaScript (WinJS) 2.0. Here we’ll ...

Android ListView – Fixing Missing/Blank Dividers
A post with code in it. Because it’s been a long time since the last one. If you work with ListViews in Android, as all Android developers will ...

Under the Hood: Rebuilding Facebook for Android - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: Rebuilding Facebook for Android geschrieben. Du kannst den vollständigen Text ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Listview ...

BitSpirit ChangeLog - BitSpirit
[Dec 29, 2010] v3.6.0.550 Stable Improved: Reduced memory usage while IPFilter.dat is enabled; Fixed: problems while running on Linux & Wine; ...

TransMac Help
TransMac Help

Aid Armenia
English HOME / CURRENT PROJECTS / PAST PROJECTS / ABOUT US Current Projects GALLERY - LISTVIEW Projects Amount Raised Amount Needed Appeal Target ...

TransMac Help
TransMac Help

AutoIt Forums
The AutoIt community forums.

Resources last updated: 12/7/2015 10:52:18 PM