I have been struggling with asp.net DetailsViews for a while, and try to figure out why asp.net LinkButton Click Event doesn't fire inside of detailsview:
See my code below:
<asp:DetailsView
ID="detailsview1"
runat="server"
GridLines="Vertical"
AutoGenerateRows="False"
HeaderStyle-BackColor="#FFFFFF"
HeaderStyle-ForeColor="White"
CellPadding="3" Height="50px"
Width="446px"
DataKeyNames="StoreNumber"
BackColor="White"
BorderColor="#cccccc"
BorderStyle="None"
BorderWidth="1px"
ForeColor="Black"
CommandRowStyle-Font-Overline="true">
<Fields>
<asp:TemplateField HeaderText="Store Number:" HeaderStyle-Font-Names ="Tahoma">
<ItemTemplate>
<asp:Label ID="lblStoreNum" ForeColor ="#ff3300" runat="server" Text='<%# Bind("StoreNumber")%>'></asp:Label>
</ItemTemplate>
<HeaderStyle Font-Names="Tahoma" />
</asp:TemplateField>
<asp:TemplateField HeaderText ="View Image">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" ToolTip ="View Image" CommandName="storage" CommandArgument='<%# Eval("StoreNumber")%>' onCommand="OpenViewPdf_Command" >
<asp:Image ID="Image4" runat="server" ImageUrl="~/Images/viewImg_.png" ImageAlign ="Middle" Width ="20" Height="15" style="border-width: 0px; margin-left : 25px"/></asp:LinkButton>
</ItemTemplate>
<HeaderStyle Font-Bold="False" Font-Names="tahoma" Font-Size="9pt" Width ="75px" />
<ItemStyle Font-Bold="False" Font-Names="tahoma" Font-Size="9pt" Width ="75px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="First Name:" HeaderStyle-Font-Names ="Tahoma">
<ItemTemplate>
<asp:Label ID="lblFName" ForeColor ="#ff3300" runat="server" Text='<%# Bind("FirstName")%>'></asp:Label>
</ItemTemplate>
<HeaderStyle Font-Names="Tahoma" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Name:" HeaderStyle-Font-Names ="Tahoma">
<ItemTemplate>
<asp:Label ID="lblLName" ForeColor ="#ff3300" runat="server" Text='<%# Bind("LastName")%>'></asp:Label>
</ItemTemplate>
<HeaderStyle Font-Names="Tahoma" />
</asp:TemplateField>
</Fields>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
</asp:DetailsView>
Protected Sub OpenViewPDF_Command(sender As Object, e As CommandEventArgs)
Dim StoreNumber As String = txtStoreNumber.Text.Trim()
Dim storenumber = e.CommandArgument
if e.commandName = "storage" then
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "key", "window.open('http://ABC/files/ & storeNumber & ".pdf','_blank');", True)
End If
End Sub
I would like the linkbutton clickEvent to work in detailsview.
Your help is much appreciated.
Thank you.