I have the code working to change a templatefield from a label to a linkbutton when the value in the label = "Y". The column is rendered as a link where the value is "Y" and as a Label when value is "N".
What do I need to do to get the 'RowCommand' to fire once I click on the linkbutton?
Code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowSorting="True"
Font-Names="Calibri" Font-Size="11pt" EmptyDataText="Make Filter Selection"
Border="3" ForeColor="#333333" Width="100%"
style="margin-top: 0px; margin-bottom: 0px; margin-right: 0px;" Height="39px"
AllowPaging = "True" PageSize = "29"
DataKeyNames="LastRefreshDate" OnPageIndexChanging = "OnPaging"
GridLines="None" CellSpacing="1" BackColor="Black"
>
<HeaderStyle BackColor="#507CD1" BorderColor="Blue" Font-Bold="True"
CssClass="DataGridFixedHeader" ForeColor="White" ></HeaderStyle>
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Parts
<asp:DropDownList ID="ddlParts" runat="server" OnSelectedIndexChanged = "ddlParts_SelectedIndexChanged"
Width="45px" AutoPostBack = "true" AppendDataBoundItems = "true" Font-Size="10pt" Font-Names="Calibri" >
<asp:ListItem Text = "ALL" Value = " " ></asp:ListItem>
</asp:DropDownList>
</HeaderTemplate>
<EditItemTemplate>
<asp:Label ID="part_kit" runat="server"
Text='<%# Eval("part_kit") %>' Width="30px"></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="part_kit" runat="server" ItemStyle-HorizontalAlign="Center"
Text='<%# Bind("part_kit") %>' Width="30px"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="gvItemCenter" Width="30px"/>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Stds
<asp:DropDownList ID="ddlStds" runat="server" OnSelectedIndexChanged = "ddlStds_SelectedIndexChanged"
Width="45px" AutoPostBack = "true" AppendDataBoundItems = "true" Font-Size="10pt" Font-Names="Calibri" >
<asp:ListItem Text = "ALL" Value = " " ></asp:ListItem>
</asp:DropDownList>
</HeaderTemplate>
<EditItemTemplate>
<asp:Label ID="STD_Kit" runat="server"
Text='<%# Eval("STD_Kit") %>' Width="30px"></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="STD_Kit" runat="server" ItemStyle-HorizontalAlign="Center"
Text='<%# Bind("STD_Kit") %>' Width="30px"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="gvItemCenter" Width="30px" />
</asp:TemplateField>
<asp:TemplateField>
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Dim clientID = ViewState("clientID")
Dim companyCd As String = ViewState("CompanyCD")
Dim bemsid = ViewState("bemsid")
Dim currentRowIndex As Integer = e.Row.RowIndex
Dim lbPartKit As New LinkButton()
If currentRowIndex > 0 Then
If currentRowIndex Mod 2 Then
GridView1.Rows(currentRowIndex - 1).BackColor = Drawing.Color.LightBlue
Else
GridView1.Rows(currentRowIndex - 1).BackColor = Drawing.Color.Cornsilk
End If
_go.RowIndex = 1
Dim key As String = GridView1.DataKeys(_go.RowIndex).Value.ToString()
LastRun.Text = GridView1.DataKeys(_go.RowIndex).Value.ToString()
End If
If currentRowIndex > 0 Then
Call GridView_SetLinkButtons(currentRowIndex)
End If
'End If
End Sub
Private Sub GridView_SetLinkButtons(currentRowIndex As Integer)
Dim strPart_Kit As String
Dim strSTDKit As String
Dim SOIString As String
Dim lbPartKit As New LinkButton()
Dim lbSTDKit As New LinkButton()
strPart_Kit = Trim(CType(GridView1.Rows(currentRowIndex - 1).FindControl("part_kit"), System.Web.UI.WebControls.Label).Text)
strSTDKit = Trim(CType(GridView1.Rows(currentRowIndex - 1).FindControl("STD_Kit"), System.Web.UI.WebControls.Label).Text)
SOIString = Trim(CType(GridView1.Rows(currentRowIndex - 1).FindControl("SOI_Number"), System.Web.UI.WebControls.Label).Text)
If strPart_Kit = "Y" Then
GridView1.Rows(currentRowIndex - 1).FindControl("part_kit").Visible = False
lbPartKit.CommandName = "PartKit"
lbPartKit.Text = strPart_Kit
lbPartKit.CausesValidation = False
lbPartKit.CommandArgument = (currentRowIndex - 1)
lbPartKit.ForeColor = System.Drawing.ColorTranslator.FromHtml("#DC143C") 'Crimson'
AddHandler lbPartKit.Command, AddressOf GridView1_RowCommand
GridView1.Rows(currentRowIndex - 1).FindControl("part_kit").Controls.Add(lbPartKit)
GridView1.Rows(currentRowIndex - 1).FindControl("part_kit").Visible = True
End If
If strSTDKit = "Y" Then
GridView1.Rows(currentRowIndex - 1).FindControl("STD_Kit").Visible = False
lbSTDKit.CommandName = "STDKit"
lbSTDKit.Text = strSTDKit
lbSTDKit.CausesValidation = False
AddHandler lbSTDKit.Command, AddressOf GridView1_RowCommand
GridView1.Rows(currentRowIndex - 1).FindControl("STD_Kit").Controls.Add(lbSTDKit)
GridView1.Rows(currentRowIndex - 1).FindControl("STD_Kit").Visible = True
End If
End Sub
tks