My page has two approaches to adding a date to a text box inside the gridview. The user can set a date for all the rows by choosing a date and clicking a button. The code behind updates each row. This is working fine. Now I want to add the calendar to each row.
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="ajaxToolkit" %>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
This is outside the gridview and working fine.
<asp:TextBox ID="SetDateTextBox" runat="server"></asp:TextBox>
<ajaxToolkit:PopupControlExtender ID="SetDateTextBox_PopupControlExtender" runat="server" BehaviorID="SetDateTextBox_PopupControlExtender"
DynamicServicePath="" ExtenderControlID="" TargetControlID="SetDateTextBox" PopupControlID="Panel1" Position="Bottom">
</ajaxToolkit:PopupControlExtender>
<asp:Panel ID="Panel1" runat="server" Width="200px">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="Black" BorderStyle="Solid" CellSpacing="1" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="250px" NextPrevFormat="ShortMonth" Width="330px">
<DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" Height="8pt" />
<DayStyle BackColor="#CCCCCC" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#333399" ForeColor="White" />
<TitleStyle BackColor="#333399" BorderStyle="Solid" Font-Bold="True" Font-Size="12pt" ForeColor="White" Height="12pt" />
<TodayDayStyle BackColor="#999999" ForeColor="White" />
</asp:Calendar>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
Now the problem. I added the calendarExtender to each row inside the templatefield.
<asp:TemplateField HeaderText="FINISH DATE" SortExpression="SCHED_FINISH_DATE">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("SCHED_FINISH_DATE", "{0:d}") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="FinishDateTextBox" runat="server" Text='<%# Bind("SCHED_FINISH_DATE", "{0:d}") %>' ClientIDMode="AutoID"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="FinishDateTextBox_CalendarExtender" runat="server" BehaviorID="FinishDateTextBox_CalendarExtender"
TargetControlID="FinishDateTextBox"/>
</ItemTemplate>
</asp:TemplateField>
I set the textbox ClientIDMode to AutoID. The page loads without error. I click the textbox on row 1 and the calendar works great. Click row 2 and beyond and the calendar does not appear.
I removed the popupcontrolextender along with the asp:panel and asp:UpdatePanel and replaced with the following code. This calendar will set a global change to all rows. So much cleaner.
<asp:TextBox ID="SetDateTextBox" runat="server"></asp:TextBox>
<ajaxtoolkit:calendarextender ID="CalendarEntender2" runat="server" TargetControlID="SetDateTextBox" />
Then inside the gridview.
<asp:TemplateField HeaderText="FINISH DATE" SortExpression="SCHED_FINISH_DATE" ItemStyle-Width="100">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("SCHED_FINISH_DATE", "{0:d}") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="FinishDateTextBox" ClientIDMode="AutoID" runat="server" Text='<%# Bind("SCHED_FINISH_DATE", "{0:d}") %>'></asp:TextBox>
<ajaxtoolkit:calendarextender ID="CalendarEntender1" runat="server" TargetControlID="FinishDateTextBox" />
</ItemTemplate>
<ItemStyle Width="100px"></ItemStyle>
</asp:TemplateField>
I still don't understand why the popupextender was causing an issue.
Related
please excuse this potentially long post as I feel like most of the information I will add below is necessary. As the title states I am trying to loop through a collection of controls that are within a gridview on my page (there are 2 gridviews actually, but they are identical in behavior) and store the values of some of these controls in an array that I can use to perform other functions.
To start I have added the code for the gridview below.
<asp:Panel ID="gridPNL1" runat="server">
Repair / Labor<asp:LinkButton runat="server" ID="lbAddRepair" Text="Add New Repair / Labor" CommandName="AddLabor" OnClick="AddObject_Click" Enabled="false" style="margin-left:20px" Visible="false" />
<asp:GridView ID="GridView1" runat="server"
EmptyDataText="No Claimed Labor" AutoGenerateColumns="False"
ShowHeaderWhenEmpty="True" DataKeyNames="RecID"
ShowFooter="True" DataSourceID="SqlDataSource6" Width="95%">
<RowStyle HorizontalAlign="Center" />
<EmptyDataTemplate>
<asp:DropDownList ID="ddlRepairEquipmentNew" runat="server" DataSourceID="SqlDataSourcePartEquipment" DataValueField="RecID"
DataTextField="EquipmentPart" AppendDataBoundItems="True" AutoPostBack="True" Width="220px" Height="20px"
Style="margin-left: 70px;" > <%-- Removed the OnSelectedIndexChanged (add if needed) --%>
<asp:ListItem Value ="0">---SELECT---</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlRepairNew" runat="server" DataSourceID="SqlDataSourceRepair" DataValueField="RecID"
DataTextField="Description" AppendDataBoundItems="True" Width="220px" Height="20px" AutoPostBack="true"
style="" OnSelectedIndexChanged="ddlRepairNew_SelectedIndexChanged"
OnDataBinding="ddlRepairNew_DataBinding">
<asp:ListItem Value="0">---SELECT---</asp:ListItem>
</asp:DropDownList>
<%-- <asp:textbox ID="txtDescOther" runat="server" Width="235px" Visible="false" />--%>
<asp:textbox runat="server" ID="txtRepairHoursNew" Width="95px" style="margin-left: 68px"/>
<%--<asp:Label runat="server" ID="lblRepairHoursAllowed"></asp:Label>--%>
<asp:HiddenField runat="server" ID="hidAllowedRepairHoursNew" />
<%-- <asp:textbox ID="txtAllowedHoursNew" runat="server" Width="90px"/>--%>
<asp:textbox ID="txtRepairCostNew" runat="server" Width="95px" ReadOnly="True"/>
<asp:textbox ID="txtLineTotalNew" runat="server" Width="95px" ReadOnly="true"/>
<asp:textbox ID="txtTaxNew" runat="server" Width="95px" text="0"/>
<asp:Button ID="InsertDetail" runat="server" CommandName="InsertDetail" Height="25px" Text="Add Detail" Width="85px" />
</EmptyDataTemplate>
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:CommandField ShowEditButton="True" footertext="Add -->" ShowDeleteButton="True" HeaderStyle-Width="70px"/>
<asp:BoundField DataField="RecID" HeaderText="RecID" SortExpression="RecID" ReadOnly="True" Visible="False" />
<asp:TemplateField HeaderText="Equipment / Repair / Labor Description" ItemStyle-HorizontalAlign="center" >
<ItemTemplate>
<asp:Label ID="lblRepairEquipmentType" Text='<%# Bind("EquipmentType") %>' runat="server" Enabled="False" Width="220px" />
<asp:label ID="lblRepairType" Text='<%# Bind("RepairType") %>' runat="server" Enabled="False" Width="220px"/>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlRepairEquipmentEdit" runat="server" DataSourceID="SqlDataSourcePartEquipment" DataValueField="RecID" DataTextField="EquipmentPart" SelectedValue='<%# Eval("EquipmentID") %>' AppendDataBoundItems="True" AutoPostBack="True" Width="220px" Height="20px" >
<asp:ListItem Value="0">---SELECT---</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlRepairEdit" runat="server" DataSourceID="SqlDataSourceRepair" DataValueField="RecID" DataTextField="Description" SelectedValue='<%# Eval("RepairID")%>' AppendDataBoundItems="True" AutoPostBack="true" Width="220px" Height="20px" OnSelectedIndexChanged="ddlRepairEdit_SelectedIndexChanged" />
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlRepairEquipmentInsert" runat="server" DataSourceID="SqlDataSourcePartEquipment" DataValueField="RecID" DataTextField="EquipmentPart" AppendDataBoundItems="True" AutoPostBack="True" Width="220px" Height="20px" Style="margin-left: 29px" >
<asp:ListItem Value="0">---SELECT---</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlRepairInsert" runat="server" DataSourceID="SqlDataSourceRepair" DataValueField="RecID" DataTextField="Description" AppendDataBoundItems="True" autopostback="true" Width="220px" Height="20px" OnSelectedIndexChanged="ddlRepairInsert_SelectedIndexChanged" OnDataBinding="ddlRepairInsert_DataBinding">
<asp:ListItem Value="0">---SELECT---</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Repair Hours Requested" ItemStyle-HorizontalAlign="center" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:label ID="lblRepairHours" Text='<%# Bind("RepairHours")%>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="txtRepairHoursEdit" Text='<%# Bind("RepairHours")%>' runat="server" Width="95px" />
<%--<asp:Label ID="lblRepairHoursEdit" runat="server"></asp:Label>--%>
<asp:HiddenField runat="server" ID="hidAllowedRepairHoursEdit" Value='<%# Bind("AllowedHours")%>' />
</EditItemTemplate>
<FooterTemplate>
<asp:textbox ID="txtRepairHoursInsert" runat="server" style="width: 100%; box-sizing: border-box;"/>
<%--<center><asp:Label ID="lblRepairHoursInsert" runat="server"></asp:Label></center>--%>
<asp:HiddenField runat="server" ID="hidAllowedRepairHoursInsert" />
</FooterTemplate>
</asp:TemplateField>
<%--<asp:TemplateField HeaderText="Repair Hours Approved" ItemStyle-HorizontalAlign="center" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:label ID="lblAllowedHours" Text='<%# Bind("AllowedHours")%>' runat="server" Width="50px"/>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="txtAllowedHoursEdit" Text='<%# Bind("AllowedHours")%>' Enabled="true" runat="server" Width="50px"/>
</EditItemTemplate>
<FooterTemplate>
<asp:textbox ID="txtAllowedHoursInsert" Text='<%# Bind("AllowedHours")%>' runat="server" style="width: 100%; box-sizing: border-box;"/>
</FooterTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="Repair Cost" ItemStyle-HorizontalAlign="center" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:label ID="lblRepairCost" Text='<%# Bind("RepairCost", "{0:C}") %>' runat="server" Enabled="False"/>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="txtRepairCostEdit" Text='<%# Bind("RepairCost") %>' runat="server" ReadOnly="True" Width="95px"/>
</EditItemTemplate>
<FooterTemplate>
<asp:textbox ID="txtRepairCostInsert" Text='<%# Bind("RepairCost") %>' runat="server" ReadOnly="True" style="width: 100%; box-sizing: border-box;"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Repair Total" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:label ID="lblRepairTotal" Text='<%# Bind("LaborRequested", "{0:C}")%>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="txtRepairTotalEdit" Text='<%# Bind("LaborRequested")%>' Enabled="false" runat="server" Width="95px"/>
</EditItemTemplate>
<FooterTemplate>
<asp:textbox ID="txtRepairTotalInsert" Text='<%# Bind("LaborRequested") %>' runat="server" Enabled="false" style="width: 100%; box-sizing: border-box;"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tax" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:LinkButton ID="lbTaxTotal" Text='<%# Bind("Tax", "{0:C}")%>' runat="server" CommandArgument="Repair" OnClick="lblTaxTotal_Click" />
<asp:HiddenField ID="hidRepairGST" runat="server" Value='<%# Bind("GST")%>' />
<asp:HiddenField ID="hidRepairPST" runat="server" Value='<%# Bind("PST")%>' />
<asp:HiddenField ID="hidRepairQST" runat="server" Value='<%# Bind("QST")%>' />
<asp:HiddenField ID="hidRepairHST" runat="server" Value='<%# Bind("HST")%>' />
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="lblTaxTotalEdit" Text='<%# Bind("Tax")%>' Enabled="true" runat="server" Width="95px"/>
</EditItemTemplate>
<FooterTemplate>
<asp:textbox ID="txtTaxTotalInsert" runat="server" Enabled="true" text="0" style="width: 100%; box-sizing: border-box;"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Insert New" HeaderStyle-Width="85px">
<ItemTemplate>
<asp:Label ID="lblEmpty" Text="" runat="server" Width="85px"/>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="Insert" runat="server" CommandName="InsertNewDetail" Height="22px" Text="Insert" style="width: 100%; box-sizing: border-box;" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#336699" ForeColor="White" />
</asp:GridView>
<asp:Label runat="server" ID="lblErrorRepair" ForeColor="Red" />
<br />
</asp:Panel>
What I am trying to do with the gridview above is loop through some specific controls on the gridview and store their values in an array. Essentially how this gridview works is the user will enter information into a series of drop down lists and textboxes, as seen above, when the user hits the button at the end of the row (labeled "InsertDetail" and "Insert" respectively, it takes the data from the drop down list and textboxes and stores it in the labels (also above) for simpler display (this goes on for however many items the user needs to enter (usually around 2 - 5 items total)). I need a way to loop through the values in however many iterations of "lblRepairEquipmentType" there are at the time the user hits any of the "insert" buttons and store the value of each iteration of "lblRepairEquipmentType" in an array so that I can use that array to perform other procedures.
Any help would be greatly appreciated and if there is something else I can try that would be better, either efficiency wise or just for best practices I would appreciate and welcome any constructive criticism. Thank you all for your patience and willingness to help.
I have an ADD button in my FormView in ASP.NET. And I have txtName on it that should first check if the textbox is empty. If it was empty, the ADD button should message Please fill up the form.
I tried the traditional error handling in vb.net like
If txtbox.text = "" then
error msg
end if
but it is not applicable when making a web page using ASP.NET backend: VBNET.
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID" DataSourceID="SqlDataSource1" Height="92px" Width="835px" AllowPaging="True" CellPadding="3" DefaultMode="Insert" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" GridLines="Horizontal" BackImageUrl= "howto.jpg" style="margin-bottom: 12px">
<EditRowStyle BackColor="#738A9C" BorderStyle="Solid" Font-Bold="True" ForeColor="#F7F7F7" />
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<InsertItemTemplate>
<asp:Label ID="lblName" runat="server" Text="Name of Applicant" Font-Size ="10pt" Font-Names="Arial" ></asp:Label>
<asp:Label ID="lblBday" runat="server" Font-Names="Arial" Font-Size="10pt" Text="Birthday"></asp:Label>
<asp:Label ID="Gender" runat="server" Font-Names="Arial" Font-Size="10pt" Text="Gender"></asp:Label>
<br />
<asp:TextBox ID="txtName" runat="server" Height="19px" Text='<%# Bind("Name") %>' Width="216px" Font-Size ="10" Font-Names="Arial"></asp:TextBox>
<asp:TextBox ID="txtBday" runat="server" Font-Names="Arial" Font-Size="10pt" Height="19px" Text='<%# Bind("Birthday") %>' TextMode="Date" Width="216px"></asp:TextBox>
<asp:DropDownList ID="txtGender" runat="server" Height="19px" Width="222px" SelectedValue='<%# Bind("Gender") %>'>
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Label ID="lblAddress" runat="server" Font-Names="Arial" Font-Size="10pt" Text="Address"></asp:Label>
<asp:Label ID="lblContact" runat="server" Font-Names="Arial" Font-Size="10pt" Text="Contact"></asp:Label>
<br />
<asp:TextBox ID="txtAddress" runat="server" Font-Names="Arial" Font-Size="10pt" Height="19px" Text='<%# Bind("Address") %>' Width="488px"></asp:TextBox>
<asp:TextBox ID="txtContact" runat="server" Font-Names="Arial" Font-Size="10pt" Height="19px" Text='<%# Bind("Contact") %>' Width="216px"></asp:TextBox>
<br />
<br />
<br />
<asp:Label ID="lblEduc" runat="server" Font-Names="Arial" Font-Size="10pt" Text="Educational Attainment"></asp:Label>
<asp:Label ID="lblCourse" runat="server" Font-Names="Arial" Font-Size="10pt" Text="Course"></asp:Label>
<br />
<asp:DropDownList ID="txtEduc" runat="server" Height="19px" SelectedValue='<%# Bind("Education") %>' Width="495px">
<asp:ListItem>High School</asp:ListItem>
<asp:ListItem>College Diploma (2-3 years)</asp:ListItem>
<asp:ListItem>College Undergrad (4-5 years)</asp:ListItem>
<asp:ListItem>Bachelor's Degree</asp:ListItem>
<asp:ListItem Value="Master">Masteral</asp:ListItem>
<asp:ListItem>Doctor</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="txtCourse" runat="server" Font-Names="Arial" Font-Size="10pt" Height="19px" Text='<%# Bind("Course") %>' Width="216px"></asp:TextBox>
<br />
<br />
<br />
<asp:Button ID="btnAdd" runat="server" Text="ADD" Font-Bold="True" Font-Size="Medium" ForeColor="Black" BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" CausesValidation="True" ValidationGroup="Insert" Font-Names="Berlin Sans FB Demi" CommandName="Insert" />
<asp:Button ID="btnCancel" runat="server" Text="CANCEL" Font-Bold="True" Font-Names="Berlin Sans FB Demi" Font-Size="Medium" ForeColor="Black" BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" CommandName="Cancel" />
</InsertItemTemplate>
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
</asp:FormView>
You can't show that alert on a webapp, but you can use javascript in order to do it.
In code behind declare this function:
Public Sub AlertMessage(ByVal mensaje As String, ByVal pag As Page)
pag.ClientScript.RegisterStartupScript(Me.GetType(), "showConfirm", "Alerta('" & mensaje & "');", True)
End Sub
Then call it from your ADD button like this:
If txtbox.text = "" then
AlertMessage(msg, Me.Page)
end if
Hope this helps
I've learn from some research that there is other way for error handling using ASPNET. I used the validation control and validation group.
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup ="FillUp" runat="server" ControlToValidate ="txtName" ErrorMessage="Please Enter Your Name"></asp:RequiredFieldValidator><br />
<asp:Button ID="btnAdd" runat="server" Text="ADD" Font-Bold="True" Font-Size="Medium" ForeColor="Black" BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" CausesValidation="True" ValidationGroup="FillUp" Font-Names="Berlin Sans FB Demi" CommandName="Insert" />
enter image description here
I also add this code in my Web.config
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
I know, what you are thinking,"This guy has a poor desig", lol, well the important is you know the code xD
This has driven me crazy a few times in the past but I've always fudged it and moved on. Today I want to try and fix it!
I quite frequently create a GridView to display data and a FormView directly beneath in Insert mode with controls in the InsertItemTemplate corresponding to the columns in the GridView, so that it looks like the FormView is just an empty row of the GridView awaiting new data entry. This works great.
The problem is that I can never get the widths of the 'columns' (really just textboxes) in the FormView to correspond to the widths of the columns in the GridView above.
In the example below, as you can see, both the GridView and FormView have a width of 100% and, sure enough, when the page is rendered they're both exactly the same width (I gave the FormView a border briefly to check). However, even though the widths of the textboxes in the FormView are identical to the widths of the columns in the GridView, they don't display that way. The textboxes are slightly wider, and by the time you get to the right-most column the cumulative effect means that the alignment is way out.
I'm guessing the problem is something to do with border widths or some other hidden element which is being rendered, but I can't figure it out. I have to say, the amount by which the alignment is out seems more than the couple of pixels a border would affect things.
<asp:GridView ID="gvTPR" runat="server" DataSourceID="SQLTPR" AutoGenerateColumns="false" DataMember="DefaultView" DataKeyNames="TPRID" Width="100%" >
<RowStyle HorizontalAlign="Center" />
<EditRowStyle BackColor="#ccffff" />
<HeaderStyle BackColor="#013b82" ForeColor="White" />
<Columns>
<asp:BoundField DataField="TPREnteredAt" HeaderText="Entered At" ReadOnly="True" SortExpression="TPREnteredAt" ItemStyle-Width="24%" ControlStyle-Width="90%" />
<asp:BoundField DataField="TPRTemp" HeaderText="Temp" ReadOnly="True" SortExpression="TPRTemp" ItemStyle-Width="12%" ControlStyle-Width="90%"/>
<asp:BoundField DataField="TPRPulse" HeaderText="Pulse" ReadOnly="True" SortExpression="TPRPulse" ItemStyle-Width="12%" ControlStyle-Width="90%"/>
<asp:BoundField DataField="TPRRespiration" HeaderText="Respiration" ReadOnly="True" SortExpression="TPRRespiration" ItemStyle-Width="12%" ControlStyle-Width="90%"/>
<asp:BoundField DataField="TPRPCV" HeaderText="PCV" ItemStyle-Width="12%" ControlStyle-Width="90%"/>
<asp:BoundField DataField="TPRTP" HeaderText="TP" ItemStyle-Width="12%" ControlStyle-Width="90%" />
<asp:CommandField ButtonType="Button" InsertVisible="False" ShowEditButton="True" ItemStyle-Width="16%" UpdateText="Save" ControlStyle-Width="60px" />
</Columns>
<EmptyDataTemplate>
No TPR records exist
</EmptyDataTemplate>
</asp:GridView>
<asp:FormView ID="fvTPR" runat="server" DataSourceID="SQLTPR" DefaultMode="Insert" Width="100%" >
<InsertItemTemplate>
<asp:textbox ID="lblEnteredAt" runat="server" Text="Will be added automatically" Width="24%" />
<asp:TextBox ID="txtTemp" runat="server" Text='<%# Bind("TPRTemp")%>' Width="12%" />
<asp:TextBox ID="txtPulse" runat="server" Text='<%# Bind("TPRPulse")%>' Width="12%" />
<asp:TextBox ID="txtRespiration" runat="server" Text='<%# Bind("TPRRespiration")%>' Width="12%" />
<asp:TextBox ID="txtPCV" runat="server" Text='<%# Bind("TPRPCV")%>' Width="12%" />
<asp:TextBox ID="txtTP" runat="server" Text='<%# Bind("TPRTP")%>' Width="12%" />
<asp:Button ID="btnAddTPR" runat="server" Text="Save" Width="5%" />
</InsertItemTemplate>
</asp:FormView>
This renders like this:
How about using GridView footer for add funcionality? This way you will have all columns in same table and you'l get around your positioning problems.
Here is an example of how your gridview should look like:
<asp:GridView ID="gvTPR" runat="server" DataSourceID="SQLTPR" AutoGenerateColumns="False" ShowFooter="True" DataKeyNames="TPRID" Width="100%" EnableModelValidation="True">
<RowStyle HorizontalAlign="Center" />
<EditRowStyle BackColor="#ccffff" />
<HeaderStyle BackColor="#013b82" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="Entered At" SortExpression="TPREnteredAt">
<EditItemTemplate>
<asp:TextBox ID="lblEnteredAt" runat="server" Text='<%# Eval("TPREnteredAt") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("TPREnteredAt") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="90%" />
<ItemStyle Width="24%" />
<FooterTemplate>
<asp:TextBox ID="lblEnteredAt" runat="server" Text="Will be added automatically" Width="24%" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Temp" SortExpression="TPRTemp">
<EditItemTemplate>
<asp:TextBox ID="txtTemp" runat="server" Text='<%# Eval("TPRTemp") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("TPRTemp") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtTemp" runat="server" Text='<%# Bind("TPRTemp")%>' Width="12%" />
</FooterTemplate>
<ControlStyle Width="90%" />
<ItemStyle Width="12%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Pulse" SortExpression="TPRPulse">
<EditItemTemplate>
<asp:TextBox ID="txtPulse" runat="server" Text='<%# Eval("TPRPulse") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("TPRPulse") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtPulse" runat="server" Text='<%# Bind("TPRPulse")%>' Width="12%" />
</FooterTemplate>
<ControlStyle Width="90%" />
<ItemStyle Width="12%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Respiration" SortExpression="TPRRespiration">
<EditItemTemplate>
<asp:TextBox ID="txtRespiration" runat="server" Text='<%# Eval("TPRRespiration") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("TPRRespiration") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtRespiration" runat="server" Text='<%# Bind("TPRRespiration")%>' Width="12%" />
</FooterTemplate>
<ControlStyle Width="90%" />
<ItemStyle Width="12%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="PCV">
<EditItemTemplate>
<asp:TextBox ID="txtPCV" runat="server" Text='<%# Bind("TPRPCV") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("TPRPCV") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtPCV" runat="server" Text='<%# Bind("TPRPCV")%>' Width="12%" />
</FooterTemplate>
<ControlStyle Width="90%" />
<ItemStyle Width="12%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="TP">
<EditItemTemplate>
<asp:TextBox ID="txtTP" runat="server" Text='<%# Bind("TPRTP") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("TPRTP") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtTP" runat="server" Text='<%# Bind("TPRTP")%>' Width="12%" />
</FooterTemplate>
<ControlStyle Width="90%" />
<ItemStyle Width="12%" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="lnkbtnEdit" runat="Server" Text="Edit" CommandName="Edit"
CausesValidation="false"></asp:Button>
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="lnkbtnUpdate" runat="Server" Text="Save" CommandName="Update"
CausesValidation="true"></asp:Button><br />
<asp:LinkButton ID="lnkbtnCancel" runat="Server" Text="Cancel" CommandName="Cancel"
CausesValidation="false"></asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="lnkbtnInsert" runat="Server" Text="Save" CommandName="Insert"
CausesValidation="true"></asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
No TPR records exist
</EmptyDataTemplate>
</asp:GridView>
Hope this helps!
Regards,
Uros
I have a grid to update the employee's confirmation. I need to change the data from grid using edit and delete link. I have trouble to create this grid. Because gridview all textbox enable always.Textbox only enable when am click the edit button.
This is my partial code:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
Width="100%" AutoGenerateColumns="False" CssClass="GridViewStyle" GridLines="None"
ShowHeaderWhenEmpty="True" EmptyDataText="No Data Found"
onpageindexchanging="GridView1_PageIndexChanging"
AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating" >
<Columns>
<asp:TemplateField HeaderText="EMP ID">
<ItemTemplate>
<asp:TextBox ID="lblempId" runat="server" Text='<%#Bind("fldemp_id") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EMPLOYEE NAME">
<ItemTemplate>
<asp:TextBox ID="lblusername" runat="server" Text='<%#Bind("fldempname") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="JOINDATE">
<ItemTemplate>
<asp:TextBox ID="lbljoin" runat="server" Text='<%#Bind("fldjoindate") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CONFIRMATION DATE">
<ItemTemplate>
<asp:TextBox ID="lblconfirm" runat="server" Text='<%#Bind("fldconfirmdate") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="STATUS">
<ItemTemplate>
<asp:TextBox ID="lblStatus" runat="server" Text='<%#Bind("fldstatus") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CONFIRMATION STATUS">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Eval("fldcon_status") %>' >
<asp:ListItem>Confirmed</asp:ListItem>
<asp:ListItem>Not-Confirmed</asp:ListItem>
<asp:ListItem>Extended</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderImageUrl="~/images/edit.png">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/edit.png" CommandName="edi"
CommandArgument='<%#Bind("fldemp_id") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderImageUrl="~/images/Delete.png">
<ItemTemplate>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/Delete.png"
CommandName="del" CommandArgument='<%#Bind("fldemp_id") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle CssClass="RowStyle" />
<EmptyDataRowStyle CssClass="EmptyRowStyle" />
<PagerStyle CssClass="PagerStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<HeaderStyle CssClass="HeaderStyle" HorizontalAlign="Left" />
<EditRowStyle CssClass="EditRowStyle" />
<AlternatingRowStyle CssClass="AltRowStyle" />
</asp:GridView>
If you're asking how to disable editing in the grid until someone hits an Edit button, simply set Enabled property to False on the grid until your button is pressed.
I have a VB.NET / ASP.NET web application. I added a dropdownlist into FooterTemplate of a Gridview. And I used ajax for postbacks. But when I add the dropdown to the triggers, vs gives me that error :
A control with ID 'DropDownList2' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.
ASP.NET code is like that :
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView2" runat="server" Width="329px" AutoGenerateColumns="False"
Font-Names="Arial" Font-Size="11pt"
AlternatingRowStyle-BackColor="#C2D69B" HeaderStyle-BackColor="green"
AllowPaging="True" ShowFooter="True" OnPageIndexChanging="OnPaging"
Style="margin-right: 0px" BackColor="White" BorderColor="#336666"
BorderStyle="Double" BorderWidth="3px" CellPadding="3"
GridLines="Horizontal">
<AlternatingRowStyle BackColor="#C2D69B" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="lnkRemove" runat="server" CommandArgument='<%# Eval("il_ad")%>'
OnClientClick="return confirm('SİLMEK İSTEDİĞİNİZDEN EMİN MİSİNİZ?')"
Text="SİL" OnClick="DeleteDURUM"></asp:Button>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnAdd" runat="server" Text="EKLE" OnClick="AddNewDURUM" />
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField EditText="DEĞİŞTİR" ButtonType="Button"
CancelText="İPTAL" DeleteText="SİL" UpdateText="KAYDET" ControlStyle-Width="70PX"
CausesValidation="False">
<ControlStyle Width="70px" />
</asp:CommandField>
<asp:TemplateField ItemStyle-Width="30px" HeaderText="YTM No">
<ItemTemplate>
<asp:Label ID="lblytm_id" runat="server" Text='<%# Eval("ytm_id")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="30px"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="İl">
<ItemTemplate>
<asp:Label ID="il_ad" runat="server" Text='<%# Eval("il_ad")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="il_ad" runat="server" Text='<%# Eval("il_ad")%>'></asp:TextBox>
</EditItemTemplate>
<!-- Dropdownlist is here : -->
<FooterTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" Width= "120px" DataSourceID="iller_yukle" AutoPostBack="True">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#333333" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#336666" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#000066" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#487575" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#275353" />
</asp:GridView>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridView2" />
<asp:AsyncPostBackTrigger ControlID="DropDownList2" /> <!-- Error is here -->
</Triggers>
</asp:UpdatePanel>
where is the mistake, I couldn't figure it out, thanks..
The DropDownList only exists within the GridView and you cannot access controls within a GridView directly.
You would need to dynamically add the trigger to the UpdatePanel after you have bound the GridView.
To dynamically add it you would need to first Bind your gridview, then register the trigger
AsyncPostBackTrigger apt = new AsyncPostBackTrigger();
apt.ControlID = ((Button)this.GridView1.FooterRow.FindControl("btnTrigger")).UniqueID;
apt.EventName = "Click";
this.UpdatePanel1.Triggers.Add(apt);
In this example I am using a button's click event to trigger the UpdatePanel. You can adapt this to the DropDownList
Generally the mistake is that you don't need to specify triggers for controls inside an UpdatePanel till you don's set ChildrenAsTriggers="false" on that UpdatePanel