Hello,
I have this issue with ASP.Net where i have to click my link button twice to get my controls to display. Can anyone take a look at my code to tell me why? This is a somewhat urgent request.
My goal is to only show the footer row when one of the linkbuttons are clicked. In the code below, when the Insert_T link button is clicked the entire footer row with drop downs and textboxes (not labels) should display. The footer row displays and I know the data is there, but the controls don't display until the second click.
I just posted a portion of the vb code since all the buttons work the same way.
thanks!!
Jenise
ASPX code:
<asp:GridView ID="gv_CurrentPlan"
runat="server"
AutoGenerateColumns="false"
DataSourceID="SqlDataSource"
DataKeyNames="DID,TID,BU_PK,PL_PK"
CellPadding="5"
OnRowDataBound="gv_CurrentPlan_RowDataBound"
OnRowUpdating="gv_CurrentPlan_RowUpdating"
ShowFooter="false"
showHeader="true"
HorizontalAlign="Left">
<Columns>
<asp:TemplateField HeaderText="Technology">
<EditItemTemplate>
<asp:DropDownList ID="ddlTech"
runat="server"
AutoPostBack="true"
DataSourceID="SqlDS_Tech"
DataTextField="Technology"
DataValueField="TID"
OnSelectedIndexChanged="ddlTech_SelectedIndexChanged" />
<asp:SqlDataSource ID="SqlDS_Tech"
runat="server"
ConnectionString="<%$ ConnectionStrings:AnnualPlan %>"
SelectCommand="Select dbo.tblTechnology.TID, dbo.tblTechnology.Technology FROM dbo.tblTechnology ORDER BY dbo.tblTechnology.Technology" >
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblTech" runat="server" text='<%# Eval("Technology") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTech_f" runat="server" Visible="false" />
<asp:DropDownList ID="ddlTech_f"
runat="server"
AutoPostBack="true"
DataSourceID="SqlDS_Tech_f"
DataTextField="Technology"
DataValueField="TID"
AppendDataBoundItems="true"
Visible="false"
OnSelectedIndexChanged="ddlTech_f_SelectedIndexChanged">
<asp:ListItem Value="0">Select Technology</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDS_Tech_f"
runat="server"
ConnectionString="<%$ ConnectionStrings:AnnualPlan %>"
SelectCommand="Select dbo.tblTechnology.TID, dbo.tblTechnology.Technology FROM dbo.tblTechnology ORDER BY dbo.tblTechnology.Technology" >
</asp:SqlDataSource>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FY Target$">
<EditItemTemplate>
<asp:TextBox ID="txtTechTarget" runat="server" Text='<%# Bind("Target") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblTechTarget" runat="server" Text='<%# Eval("Target") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTechTarget_f" runat="server" visible="false" />
<asp:TextBox ID="txtTechTarget_f" runat="server" Text='<%# Bind("Target") %>' Visible="false" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Business Unit">
<EditItemTemplate>
<asp:DropDownList ID="ddlBU"
runat="server"
AutoPostBack="true"
DataTextField="BU"
DataValueField="BID"
DataSourceID="SqlDS_BU"
AppendDataBoundItems="true"
OnSelectedIndexChanged="ddlBU_SelectedIndexChanged">
<asp:ListItem Value="0">Select Business Unit</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDS_BU"
runat="server"
ConnectionString="<%$ ConnectionStrings:AnnualPlan %>"
SelectCommand="SELECT dbo.tblBusinessUnit.BID, dbo.tblBusinessUnit.BU FROM dbo.tblBUH_Hierarchy INNER JOIN dbo.tblBusinessUnit ON dbo.tblBUH_Hierarchy.BID = dbo.tblBusinessUnit.BID WHERE (dbo.tblBUH_Hierarchy.TID = @TID) GROUP BY dbo.tblBusinessUnit.BID, dbo.tblBusinessUnit.BU ORDER BY dbo.tblBusinessUnit.BU">
<SelectParameters>
<asp:Parameter Name="TID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblBU" runat="server" Text='<%# Eval("BU") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblBU_f" runat="server" Visible="false" />
<asp:DropDownList ID="ddlBU_f"
runat="server"
AutoPostBack="true"
DataTextField="BU"
DataValueField="BID"
AppendDataBoundItems="true"
DataSourceID="SqlDS_BU_f"
Visible="false"
OnSelectedIndexChanged="ddlBU_f_SelectedIndexChanged">
<asp:ListItem Value="0">Select Business Unit</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDS_BU_f"
runat="server"
ConnectionString="<%$ ConnectionStrings:AnnualPlan %>"
SelectCommand="SELECT dbo.tblBusinessUnit.BID, dbo.tblBusinessUnit.BU FROM dbo.tblBUH_Hierarchy INNER JOIN dbo.tblBusinessUnit ON dbo.tblBUH_Hierarchy.BID = dbo.tblBusinessUnit.BID WHERE (dbo.tblBUH_Hierarchy.TID = @TID) GROUP BY dbo.tblBusinessUnit.BID, dbo.tblBusinessUnit.BU ORDER BY dbo.tblBusinessUnit.BU">
<SelectParameters>
<asp:Parameter Name="TID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BU Percentage">
<EditItemTemplate>
<asp:TextBox ID="txtBUPerc" runat="server" Text='<%# Bind("BUPer") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblBUPerc" runat="server" Text='<%# Eval("BUPer") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblBUPerc_f" runat="server" Visible="false" />
<asp:TextBox ID="txtBUPerc_f" runat="server" Text='<%# Bind("BUPer") %>' Visible="false" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BU Value$">
<ItemTemplate>
<asp:Label ID="lblBUValue" runat="server" Text='<%# Eval("BUValue") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblBUValue_f" runat="server" Text='<%# Eval("BUValue") %>' />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Product Line">
<EditItemTemplate>
<asp:DropDownList ID="ddlPL"
runat="server"
AutoPostBack="true"
DataTextField="ProductLine"
DataValueField="PLID"
DataSourceID="SqlDS_PL"
AppendDataBoundItems="true">
<asp:ListItem Value="0">Select Product Line</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDS_PL"
runat="server"
ConnectionString="<%$ ConnectionStrings:AnnualPlan %>"
SelectCommand="SELECT dbo.tblProductLine.PLID, dbo.tblProductLine.ProductLine FROM dbo.tblBUH_Hierarchy INNER JOIN dbo.tblProductLine ON dbo.tblBUH_Hierarchy.TID = dbo.tblProductLine.TID WHERE (dbo.tblBUH_Hierarchy.BID = @BID) GROUP BY dbo.tblProductLine.PLID, dbo.tblProductLine.ProductLine ORDER BY dbo.tblProductLine.ProductLine">
<SelectParameters>
<asp:Parameter Name="BID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblPL" runat="server" Text='<%# Eval("ProductLine") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlPL_f"
runat="server"
AutoPostBack="true"
DataTextField="ProductLine"
DataValueField="PLID"
AppendDataBoundItems="true"
DataSourceID="SqlDS_PL_f" >
<asp:ListItem Value="0">Select Product Line</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDS_PL_f"
runat="server"
ConnectionString="<%$ ConnectionStrings:AnnualPlan %>"
SelectCommand="SELECT dbo.tblProductLine.PLID, dbo.tblProductLine.ProductLine FROM dbo.tblBUH_Hierarchy INNER JOIN dbo.tblProductLine ON dbo.tblBUH_Hierarchy.TID = dbo.tblProductLine.TID WHERE (dbo.tblBUH_Hierarchy.BID = @BID) GROUP BY dbo.tblProductLine.PLID, dbo.tblProductLine.ProductLine ORDER BY dbo.tblProductLine.ProductLine">
<SelectParameters>
<asp:Parameter Name="BID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PL Percentage">
<EditItemTemplate>
<asp:TextBox ID="txtPLPerc" runat="server" Text='<%# Bind("PLPer") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblPLPerc" runat="server" Text='<%# Eval("PLPer") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtPLPerc_f" runat="server" Text='<%# Bind("PLPer") %>' />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PL Value$">
<ItemTemplate>
<asp:Label ID="lblPLValue" runat="server" Text='<%# Eval("PLValue") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnEdit" runat="server" CausesValidation="true" CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="btnInsert_T" runat="server" CausesValidation="true" CommandName="Insert_T" Text="Add Tech" />
<asp:LinkButton ID="btnInsert_BU" runat="server" CausesValidation="true" CommandName="Insert_BU" Text="Add BU" />
<asp:LinkButton ID="btnInsert_PL" runat="server" CausesValidation="true" CommandName="Insert_PL" Text="Add PL" />
<asp:LinkButton ID="btnDelete" runat="server" CausesValidation="true" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this record?');" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnUpdate" runat="server" CausesValidation="False" CommandName="Update" Text="Update" />
<asp:LinkButton ID="btnCancel" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="btnInsert_T_f" runat="server" CausesValidation="true" CommandName="Insert" Text="Insert" Visible="false" />
<asp:LinkButton ID="btnInsert_PL_f" runat="server" CausesValidation="true" CommandName="Insert_PL2" Text="Insert" Visible="false" />
<asp:LinkButton ID="btnInsert_BU_f" runat="server" CausesValidation="true" CommandName="Insert_BU2" Text="Insert" Visible="false" />
<asp:LinkButton ID="btnCancelInsert_f" runat="server" CausesValidation="true" CommandName="Cancel" Text="Cancel" Visible="false" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblErrorFlag" runat="server" ForeColor="Red" Font-Italic="true" Font-Bold="true" Text='<%# Eval("complete_calc")%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Protected Sub gv_CurrentPlan_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gv_CurrentPlan.RowCommand
ElseIf e.CommandName = "Insert_T" AndAlso Page.IsValid Then
Dim ddlTech_f As DropDownList = CType(gv_CurrentPlan.FooterRow.FindControl("ddlTech_f"), DropDownList)
Dim txtTechTarget_f As TextBox = CType(gv_CurrentPlan.FooterRow.FindControl("txtTechTarget_f"), TextBox)
Dim ddlBU_f As DropDownList = CType(gv_CurrentPlan.FooterRow.FindControl("ddlBU_f"), DropDownList)
Dim txtBUPerc_f As TextBox = CType(gv_CurrentPlan.FooterRow.FindControl("txtBUPerc_f"), TextBox)
Dim btnIns_BU As LinkButton = CType(gv_CurrentPlan.Rows(gvRow.RowIndex).FindControl("btnInsert_BU"), LinkButton)
Dim btnIns_T As LinkButton = CType(gv_CurrentPlan.Rows(gvRow.RowIndex).FindControl("btnInsert_T"), LinkButton)
Dim btnIns_PL As LinkButton = CType(gv_CurrentPlan.Rows(gvRow.RowIndex).FindControl("btnInsert_PL"), LinkButton)
Dim btn_Edit As LinkButton = CType(gv_CurrentPlan.Rows(gvRow.RowIndex).FindControl("btnEdit"), LinkButton)
Dim btnIns_T_f As LinkButton = CType(gv_CurrentPlan.FooterRow.FindControl("btnInsert_T_f"), LinkButton)
Dim btnCancelIns_f As LinkButton = CType(gv_CurrentPlan.FooterRow.FindControl("btnCancelInsert_f"), LinkButton)
gv_CurrentPlan.ShowFooter = True
ddlTech_f.Visible = True
txtTechTarget_f.Visible = True
ddlBU_f.Visible = True
txtBUPerc_f.Visible = True
btn_Edit.Visible = False
btnIns_T.Visible = False
btnIns_BU.Visible = False
btnIns_PL.Visible = False
btnIns_T_f.Visible = True
btnCancelIns_f.Visible = True
ViewState.Add("strCmdButton", "Insert")
ViewState.Add("iDIDKey", gv_CurrentPlan.DataKeys(gvRow.RowIndex).Values(0))
VB-Code Behind:
Software/Hardware used:
ASKED:
February 23, 2009 9:53 PM
UPDATED:
February 24, 2009 11:02 PM