SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Aug 2004
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    gridviewrow access to clientid, rowindex in .ascx file

    i have a simple gridview where i want to display an itemtemplate for edit and delete buttons.

    PHP Code:
        <asp:GridView ID="GridView1" runat="server" Width="500px"
        
    ShowHeader="False" EnableTheming="False"
        
    AutoGenerateColumns="False" AutoGenerateRows="False" 
        
    DataKeyNames="id">
            <
    Columns>
                <
    asp:TemplateField>
                    <
    ItemTemplate>
                        <
    asp:Label ID="LabelName" runat="server" Text='<%# Eval("name") %>' />
                    </
    ItemTemplate>
                </
    asp:TemplateField>
                <
    asp:TemplateField>
                    <
    ItemTemplate>
                        <!-- 
    Delete -->
                        <
    button type="submit" id="Buttondelete_<%#((GridViewRow)Container).RowIndex %>">
                            <
    img src="/images/icons/delete.png" alt="Delete"/> 
                            
    Delete
                        
    </button>
                      
                        <
    script type="text/javascript">
                            
    // Instantiate the Dialog
                            
    YAHOO.namespace("knowledgebase.categories.actionDelete");

                            function 
    knowledgebase_categories_init() {
                                                            
                                
    // Define various event handlers for Dialog
                                
    var handleYes = function() {
                                    
    alert("You clicked yes!");
                                    
    this.hide();
                                };
                                var 
    handleNo = function() {
                                    
    this.hide();
                                };
                                var 
    OnTrigger = function()
                                {
                                    
    this.show();
                                }
                                

                                
    // Instantiate the Dialog
                                
    YAHOO.knowledgebase.categories.actionDelete.simpledialog1 
                                        new 
    YAHOO.widget.SimpleDialog("simpledialog1"
                                                         { 
    width"300px",
                                                           
    fixedcentertrue,
                                                           
    visiblefalse,
                                                           
    draggablefalse,
                                                           
    closetrue,
                                                           
    text"Do you want to continue?",
                                                           
    iconYAHOO.widget.SimpleDialog.ICON_HELP,
                                                           
    constraintoviewporttrue,
                                                           
    buttons: [ { text:"Yes"handler:handleYesisDefault:true },
                                                                      { 
    text:"No",  handler:handleNo } ]
                                                         } );
                                                         
                                
    YAHOO.knowledgebase.categories.actionDelete.simpledialog1.setHeader("Are you sure?");
                                
    YAHOO.knowledgebase.categories.actionDelete.simpledialog1.render("container");
                                
    YAHOO.util.Event.addListener('Buttondelete_<%#((GridViewRow)Container).RowIndex %>''click'OnTrigger);
                            }

                            
    YAHOO.util.Event.addListener(window"load"knowledgebase_categories_init);
                                                                 
                                                                 
                        
    </script>
                        
                        
                    </ItemTemplate>    
                </asp:TemplateField> 

    but <%#((GridViewRow)Container).RowIndex %> renders to an empty string.
    I also can't seem to get the client id
    ((GridViewRow)Container).FindControl("somcontrolid").ClientID
    also yields an empty string.

    i hate to write javascript code in the .cs file.
    and avoid avoid looping as in the link below.
    http://www.sitepoint.com/forums/showthread.php?t=533444

    -lm

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Try something like this:

    Code:
                    <asp:TemplateField>
                        <ItemTemplate>
                            <input type="button" runat="server" id="DeleteButton" value="Delete" enableviewstate="false" />
                            <&#37;# ((GridViewRow)Container).FindControl("DeleteButton").ClientID %>
                        </ItemTemplate>
                    </asp:TemplateField>
    Another option, presuming the YUI supports it, would be to pass a reference into the button into the add listener function.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •