locked
Gridview Linkbutton rowcommand is not firing RRS feed

  • Question

  • User-786564416 posted

    I have a linkbutton that I want to use it on click to show a ModalPopupWindow Panel. However, it is not firing at all.

    The Gridview description is as following:

    <asp:GridView ID="GridView1" runat="server" DataSourceID="SDS2" CssClass="Grid" 
                        CellPadding="4" ForeColor="#333333" GridLines="Vertical" BackColor="#99CCFF" 
                        BorderStyle="Solid" AutoGenerateColumns="False"  
                        EmptyDataText="لا توجد أي سجلات" AllowSorting="True" OnRowCommand="GridView1_RowCommand">
                        <Columns>
    
                    
    
                            <asp:TemplateField HeaderText="الرابط">
                                <ItemTemplate>
                                    <asp:HyperLink ID="AttachmentLink" runat="server" NavigateUrl='<%# "~/" & "PdfDirectory/" & Eval("Attachments") %>' Target="_blank" ImageUrl="~/Images/Attachment1.png"  CssClass="HyperLinkStyle">
                                    </asp:HyperLink>
                                </ItemTemplate>
                                <ItemStyle BorderWidth="1px" Width="3%" HorizontalAlign="Center"  />
                            </asp:TemplateField>
    
    
                            <asp:TemplateField HeaderText="مغلق" >
                                <ItemTemplate>
                                    <asp:CheckBox ID="Closing" runat="server"   />  
                                </ItemTemplate>
                                <ItemStyle BorderWidth="1px" Width="2%" HorizontalAlign="Center" Font-Size="20px" />
                            </asp:TemplateField>
    
                            <asp:TemplateField HeaderText="الأهمية" Visible="false" >
                                <ItemTemplate>
                                    <asp:Image ID="ImportanceLevel" runat="server" ImageUrl='<%# imageUrl(Eval("Importance")) %>'  CssClass="ImageFieldStyle"   />  
                                </ItemTemplate>
                                <ItemStyle BorderWidth="1px"  HorizontalAlign="Center" />
                            </asp:TemplateField>
                                                    
                            <asp:TemplateField HeaderText="الحالة" >
                                <ItemTemplate>
                                    <asp:Label ID="Status" runat="server" CssClass="StatusFieldStyle"       />  
                                </ItemTemplate>
                                <ItemStyle BorderWidth="1px" Width="22.5%" HorizontalAlign="Right"  Font-Size="20px" />
                            </asp:TemplateField>
    
                            <asp:TemplateField HeaderText="المهلة" >
                                <ItemTemplate>
                                    <asp:Label ID="ReqAnsPed" runat="server" text='<%# Eval("RequiredAnsPeriod")  %>' CssClass="RAPFieldStyle"       />  
                                </ItemTemplate>
                                <ItemStyle BorderWidth="1px" Width="5%" HorizontalAlign="center"  Font-Size="20px" />
                            </asp:TemplateField>
    
                            <asp:TemplateField HeaderText="التاريخ" SortExpression="PostTime" >
                                <ItemTemplate>
                                    <asp:Label ID="ShownDate" runat="server" text='<%# Format((Eval("PostTime")), "dd-MMM-yyyy") %>' CssClass="DateFieldStyle"      />  
                                </ItemTemplate>
                                <ItemStyle BorderWidth="1px" Width="12.5%" HorizontalAlign="center" />
                            </asp:TemplateField>
    
                    
                            <asp:TemplateField HeaderText="الموضوع" SortExpression="Subject">
                                <ItemTemplate>
                                    <asp:Label ID="SubjectField" runat="server" CssClass="SubjectFieldStyle"   />  
                                </ItemTemplate>
                                <ItemStyle BorderWidth="1px" Width="20%" HorizontalAlign="right" />
                            </asp:TemplateField>
    
                            <asp:TemplateField HeaderText="إلى" SortExpression="TargetName">
                                <ItemTemplate>
                                    <asp:Label ID="TargetField" runat="server" text='<%# Eval("TargetName")  %>' CssClass="TargetFieldStyle"   />  
                                </ItemTemplate>
                                <ItemStyle BorderWidth="1px" Width="15%" HorizontalAlign="right" />
                            </asp:TemplateField>
                    
                            <asp:TemplateField HeaderText="من" SortExpression="SourceName">
                                <ItemTemplate>
                                    <asp:Label ID="SourceField" runat="server" text='<%# Eval("SourceName")  %>' CssClass="SourceFieldStyle"   />  
                                </ItemTemplate>
                                <ItemStyle BorderWidth="1px" Width="15%" HorizontalAlign="right" />
                            </asp:TemplateField>
    
                            <asp:TemplateField HeaderText="الرقم">
                                <ItemTemplate>
                                    <asp:linkbutton ID="HyperLink1" runat="server" 
                                        Target="_blank" CssClass="RefFieldStyle"
                                        Text='<%# Eval("LetterID") %>' CommandArgument="LetterDetails" ></asp:linkbutton>
                                </ItemTemplate>
                                <ItemStyle BorderWidth="1px" Width="5%" HorizontalAlign="Center"  />
                            </asp:TemplateField>
    
                            <asp:TemplateField>
                                <HeaderStyle Height="20px" /> 
                                <ItemTemplate>
                                    <asp:RadioButton ID="GridView1_RadioButton" runat="server"  AutoPostBack="True" GroupName="RadioGroup" OnCheckedChanged="GridView1_RadioButton_CheckedChanged" />
                                </ItemTemplate> 
                                <ItemStyle BorderWidth="1px" Width="2%" /> 
                            </asp:TemplateField>
    
                            <asp:BoundField DataField="Attachments" Visible="false" 
                                SortExpression="Attachments" >
                            </asp:BoundField>
    
            
    
                            <asp:BoundField DataField="Importance" Visible="false" 
                                SortExpression="Importance" >
                            </asp:BoundField>
    
                            <asp:TemplateField Visible="false" >
                                <ItemTemplate>
                                    <asp:Label ID="SourceIndx" runat="server" text='<%# Eval("Source")  %>'  Visible="false" />  
                                </ItemTemplate>
                            </asp:TemplateField>
    
                            <asp:TemplateField Visible="false" >
                                <ItemTemplate>
                                    <asp:Label ID="TargetIndx" runat="server" text='<%# Eval("Target")  %>'  Visible="false" />  
                                </ItemTemplate>
                            </asp:TemplateField>
    
                            <asp:TemplateField Visible="false" >
                                <ItemTemplate>
                                    <asp:Label ID="LatestPostField" runat="server" text='<%# Eval("LastPostTime")%>'  Visible="false" />  
                                </ItemTemplate>
                            </asp:TemplateField>
    
                            <asp:TemplateField Visible="false" >
                                <ItemTemplate>
                                    <asp:Label ID="PTField" runat="server" text='<%# Eval("PostType")  %>'  Visible="false" />  
                                </ItemTemplate>
                            </asp:TemplateField>
    
                            <asp:TemplateField Visible="false" >
                                <ItemTemplate>
                                    <asp:Label ID="Late" runat="server" text='<%# Eval("Late")  %>'  Visible="false" />  
                                </ItemTemplate>
                            </asp:TemplateField>
    
                            <asp:TemplateField Visible="false" >
                                <ItemTemplate>
                                    <asp:Label ID="AnsweringLetterField" runat="server" text='<%# Eval("AnsweringLetterID")%>'  Visible="false" />  
                                </ItemTemplate>
                            </asp:TemplateField>
    
                        </Columns> 
                        
                        <EditRowStyle BackColor="#999999" />
                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        <SortedAscendingCellStyle BackColor="#E9E7E2" />
                        <SortedAscendingHeaderStyle BackColor="#506C8C" />
                        <SortedDescendingCellStyle BackColor="#FFFDF8" />
                        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                        <EmptyDataTemplate>
                            <div class="EmptyDataRowStyle">
                                لا توجد أي سجلات
                            </div> 
                        </EmptyDataTemplate>
                
    
                    </asp:GridView>

    The GridView1_rowcommand( ) which is not firing at all, is as following:

    Protected Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles GridView1.RowCommand
    
            If e.CommandName = "LetterDetails" Then
    
            End If
    
        End Sub

    Where is the problem?

    Thursday, March 28, 2019 5:48 PM

All replies

  • User839733648 posted

    Hi alihusain_77,

    According to your description and code, I've found that you have missed the attribute CommandName of your Linkbutton.

    I've added a label to the page to test.

                            <asp:TemplateField HeaderText="الرقم">
                                <ItemTemplate>
                                    <asp:linkbutton ID="HyperLink1" runat="server" 
                                        Target="_blank" CssClass="RefFieldStyle"
                                        Text='<%# Eval("LetterID") %>' CommandArgument="LetterDetails" CommandName="LetterDetails"></asp:linkbutton>
                                </ItemTemplate>
                                <ItemStyle BorderWidth="1px" Width="5%" HorizontalAlign="Center"  />
                            </asp:TemplateField>
    ......
    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles GridView1.RowCommand
        If e.CommandName = "LetterDetails" Then
            Label1.Text = "You've clicked the link button"
        End If
    End Sub

    result:

    Best Regards,

    Jenifer

    Friday, March 29, 2019 2:41 AM