Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a GridView in which I have textboxes with calendar extendar. I am facing a strange problem.. The calendar extender works ok for the first row of the GridView but it does not work.
ASPX CODE is as below:(sorry, I know it's a long code.)
<asp:TabContainer AutoPostBack="false" ID="TabContainer_Main" Height="270px" runat="server">
<asp:TabPanel ID="TabPanel__TravelLine" runat="server" HeaderText="Travel Line">
<ContentTemplate>
<div id="div_TravelLine">
<asp:UpdatePanel ID="upPanel_TravelLine" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel_TravelLine" runat="server">
<asp:GridView ID="grvTravelLine" CssClass="tabledata" runat="server" ShowFooter="True"
AutoGenerateColumns="False" ShowHeaderWhenEmpty="True" Width="100%" OnRowDataBound="grvTravelLine_RowDataBound">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
<asp:TemplateField HeaderText="From City">
<ItemTemplate>
<asp:TextBox MaxLength="50" Text='<%# Eval("From_City") %>' onkeypress="return Alpha(event);"
ID="txtFrmCity_TravelLine" Width="70px" CssClass="txtbox" runat="server"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="To City">
<ItemTemplate>
<asp:TextBox ID="txtToCity_TravelLine" Text='<%# Eval("To_City") %>' onkeypress="return Alpha(event);"
MaxLength="50" Width="70px" CssClass="txtbox" runat="server"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Travel Mode">
<ItemTemplate>
<asp:DropDownList ID="ddlTravelMode_TravelLine" Width="100px" CssClass="drpdown"
runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Travel Date">
<ItemTemplate>
<asp:TextBox ID="txtTravelDt_TravelLine" Text='<%# Eval("TravelDt") %>' Width="70px"
runat="server" ClientIDMode="Static" CssClass="FormText"></asp:TextBox>
<asp:CalendarExtender
ID="Cal_txtTravelDt" CssClass="MyCalendar" runat="server" Format="yyyy/MM/dd"
TargetControlID="txtTravelDt_TravelLine">
</asp:CalendarExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Booking Date">
<ItemTemplate>
<asp:TextBox ID="txtBookingDt_TravelLine" Text='<%# Eval("BookingDt") %>' runat="server"
ClientIDMode="Static" CssClass="FormText"></asp:TextBox><asp:CalendarExtender ID="Cal_txtBookingDt"
CssClass="MyCalendar" runat="server" Format="yyyy/MM/dd" TargetControlID="txtBookingDt_TravelLine">
</asp:CalendarExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Arrival Date">
<ItemTemplate>
<asp:TextBox ID="txtArrivalDt_TravelLine" Text='<%# Eval("ArrivalDt") %>' runat="server"
ClientIDMode="Static" CssClass="FormText"></asp:TextBox><asp:CalendarExtender ID="Cal_txtArrivalDt"
CssClass="MyCalendar" runat="server" Format="yyyy/MM/dd" TargetControlID="txtArrivalDt_TravelLine">
</asp:CalendarExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:TextBox ID="txtAmount_TravelLine" AutoPostBack="true" OnTextChanged="txtAmount_TravelLine_OnTextChanged"
Text='<%# Eval("Amount") %>' MaxLength="7" Width="200px" onblur="Fixed(this);"
CssClass="txtbox" runat="server"></asp:TextBox><asp:FilteredTextBoxExtender ID="ftbetxtAmount_TravelLine"
runat="server" TargetControlID="txtAmount_TravelLine" FilterMode="ValidChars"
FilterType="Custom" ValidChars="0123456789.">
</asp:FilteredTextBoxExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="D">
<ItemTemplate>
<asp:LinkButton ID="lnkDel" runat="server" OnCommand="DeleteRowHandler_TravelLine"
Text="D"></asp:LinkButton></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<br />
<table width="100%">
<tr>
<td align="left">
<asp:LinkButton ID="LnkAddTravelLineToGrv" runat="server" Font-Bold="True" ForeColor="#3366FF"
OnClick="LnkAddTravelLineToGrv_Click">Click To Add</asp:LinkButton><b>
(Note: D = Delete) </b>
</td>
<td align="right">
<b>Grand Total: </b>
<asp:TextBox ID="txtgrandtotal" Style="text-align: right;" runat="server" ClientIDMode="Static"
CssClass="FormText" Width="80px"></asp:TextBox>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="LnkAddTravelLineToGrv" />
</Triggers>
</asp:UpdatePanel>
</div>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel_LodgingNLiving" runat="server" HeaderText="Lodging & living">
<ContentTemplate>
<div id="div_LodgingNLiving">
<asp:UpdatePanel ID="UpPanel_LodgingNLiving" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lnkAddLodgingLivingToGrv" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Panel ID="Panel_LodgingLiving" runat="server">
<asp:GridView ID="grvLodgingLiving" OnRowDataBound="grvLodgingLiving_RowDataBound"
CssClass="tabledata" runat="server" ShowFooter="True" AutoGenerateColumns="False"
ShowHeaderWhenEmpty="True" Width="100%">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
<asp:TemplateField HeaderText="City">
<ItemTemplate>
<asp:TextBox MaxLength="50" Text='<%# Eval("City") %>' onkeypress="return Alpha(event);"
ID="txtCity_LodgingNLiving" Width="80px" CssClass="txtbox" runat="server"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Lodging Nights">
<ItemTemplate>
<asp:TextBox Text='<%# Eval("Lodging_Nights") %>' ID="txtLodgingNights_LodgingNLiving"
onkeypress="return OnlyNum(event);" Width="50px" MaxLength="3" CssClass="txtbox"
runat="server"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Lodging Days">
<ItemTemplate>
<asp:TextBox Text='<%# Eval("Lodging_Days") %>' ID="txtLodgingDays_LodgingNLiving"
onkeypress="return OnlyNum(event);" Width="50px" MaxLength="3" CssClass="txtbox"
runat="server"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Hotel/Lodge Name">
<ItemTemplate>
<asp:TextBox Text='<%# Eval("Hotel_LodgeName") %>' MaxLength="50" onkeypress="return Alpha(event);"
ID="txtHotelLodgename_LodgingNLiving" CssClass="txtbox" runat="server"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Check-In Date">
<ItemTemplate>
<asp:TextBox Text='<%# Eval("CheckInDt") %>' ID="txtCheckinDt_LodgingNLiving" runat="server"
ClientIDMode="Static" CssClass="FormText"></asp:TextBox><asp:CalendarExtender ID="Cal_txtCheckinDt_LodgingNLiving"
CssClass="MyCalendar" runat="server" Format="yyyy/MM/dd" TargetControlID="txtCheckinDt_LodgingNLiving" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Check-Out Date">
<ItemTemplate>
<asp:TextBox Text='<%# Eval("CheckOutDt") %>' ID="txtCheckoutDt_LodgingNLiving" runat="server"
ClientIDMode="Static" CssClass="FormText"></asp:TextBox><asp:CalendarExtender ID="CaltxtCheckoutDt_LodgingNLiving"
CssClass="MyCalendar" runat="server" Format="yyyy/MM/dd" TargetControlID="txtCheckoutDt_LodgingNLiving" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Remark">
<ItemTemplate>
<asp:TextBox Text='<%# Eval("Remark") %>' CssClass="txtbox" ID="txtRemark_LodgingNLiving"
runat="server" Height="50px" Width="80px" MaxLength="100"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:TextBox Text='<%# Eval("Amount") %>' AutoPostBack="true" OnTextChanged="txtAmount_LodgingNLiving_OnTextChanged"
MaxLength="7" ID="txtAmount_LodgingNLiving" Width="70px" onblur="Fixed(this);"
CssClass="txtbox" runat="server"></asp:TextBox><asp:FilteredTextBoxExtender ID="Ftb_txtAmount_LodgingNLiving"
runat="server" TargetControlID="txtAmount_LodgingNLiving" FilterMode="ValidChars"
FilterType="Custom" ValidChars="0123456789.">
</asp:FilteredTextBoxExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="D">
<ItemTemplate>
<asp:LinkButton ID="lnkDel" runat="server" OnCommand="DeleteRowHandler_LodgingLiving"
Text="D"></asp:LinkButton></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<br />
<table width="100%">
<tr>
<td align="left">
<asp:LinkButton ID="lnkAddLodgingLivingToGrv" OnClick="LnkAddLodgingLivingToGrv_Click"
runat="server" Font-Bold="True" ForeColor="#3366FF">Click To Add</asp:LinkButton><b>
(Note: D = Delete) </b>
</td>
<td align="right">
<b>Grand Total: </b>
<asp:TextBox ID="txtGrandTotal_LodgingLiving" Style="text-align: right;" runat="server"
ClientIDMode="Static" CssClass="FormText" Width="80px"></asp:TextBox>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel_IncidentalCost" runat="server" HeaderText="Incidental Cost">
<ContentTemplate>
<div id="div_IncidentalCost">
<asp:UpdatePanel ID="UpPanel_IncidentalCost" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="LnkAddIncidentalCostToGrid" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Panel ID="Panel_IncidentalCost" runat="server">
<asp:GridView ID="grvIncidentalCost" OnRowDataBound="grvIncidentalCost_RowDataBound"
CssClass="tabledata" runat="server" ShowFooter="True" AutoGenerateColumns="False"
ShowHeaderWhenEmpty="True" Width="100%">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Place">
<ItemTemplate>
<asp:TextBox MaxLength="50" Text='<%# Eval("Place") %>' onkeypress="return Alpha(event);"
ID="txtPlace_IncidentalCost" Width="200px" CssClass="txtbox" runat="server"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:TextBox ID="txtAmount_IncidentalCost" MaxLength="7" Text='<%# Eval("Amount") %>'
Width="200px" onblur="Fixed(this);" CssClass="txtbox" runat="server"></asp:TextBox><asp:FilteredTextBoxExtender
ID="Ftb_txtAmount_IncidentalCost" runat="server" TargetControlID="txtAmount_IncidentalCost"
FilterMode="ValidChars" FilterType="Custom" ValidChars="0123456789.">
</asp:FilteredTextBoxExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Remark">
<ItemTemplate>
<asp:TextBox CssClass="txtbox" AutoPostBack="true" OnTextChanged="txtRemark_IncidentalCost_OnTextChanged"
Text='<%# Eval("Remark") %>' ID="txtRemark_IncidentalCost" runat="server" Height="50px"
TextMode="MultiLine" Width="463px" MaxLength="100"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="D">
<ItemTemplate>
<asp:LinkButton ID="lnkDel" runat="server" OnCommand="DeleteRowHandler_IncidentalCost"
Text="D"></asp:LinkButton></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<br />
<table width="100%">
<tr>
<td align="left">
<asp:LinkButton ID="LnkAddIncidentalCostToGrid" runat="server"
Font-Bold="True" ForeColor="#3366FF"
OnClick="LnkAddIncidentalCostToGrid_Click">
Click To Add</asp:LinkButton>
<b>
(Note: D = Delete) </b>
</td>
<td align="right">
<b>Grand Total: </b>
<asp:TextBox ID="txtGrandTotal_IncidentalCost"
Style="text-align: right;" runat="server"
ClientIDMode="Static" CssClass="FormText" Width="80px"></asp:TextBox>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
Problem is your ClientIDMode property on Textboxes
ClientIDMode="Static"
You need to remove abvoe attribute from your GridView code, because if you use it, all your TextBox controls will have the same ID, "txtCheckoutDt_LodgingNLiving" for this particular control on it calender extender is set. The CalendarExtender controls will find the first value (which is on the first row) and will be all mapped to it.
If you want to refine the patterns of your control ID assignment, here's more about the topic.
Related
I am using asp.net c# webform and i am using datagridviews , I searched and i found the property in windows form
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
But in web form this property not used.
How can i make my datagridview dynamically change columns width and size when open my website from mobile or ipad window?
After one week of trying I found the following solution and its working correct on mobile screen by adding scroll bar and width = 100% to the div and put datagridview also in div ,this is the code i used :
<div style="overflow:scroll">
<asp:GridView ID="GridViewHome" runat="server" Width="100%" AutoGenerateColumns="false" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" OnPageIndexChanging="GridViewHome_PageIndexChanging" PageSize="30" ShowFooter="True">
<Columns>
<asp:TemplateField>
<HeaderTemplate>Options</HeaderTemplate>
<ItemTemplate>
<div style="width:100%"> <asp:HyperLink ID="HyperLink1" NavigateUrl='<%#"/RPT/WebForm1.aspx?order_id=" +Eval("Request number")+"&DEPT ID=" +Eval("DEPT ID")+"&Test Id=" +Eval("Test Id")+"&Culture=" +Eval("Culture")%>' runat="server">Print Result</asp:HyperLink></div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Patient MRN#</HeaderTemplate>
<ItemTemplate>
<div style="width:100%"> <asp:Label ID="lblpatient" runat="server" Text='<%# Eval("Patient No") %>'></asp:Label></div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Patient Name</HeaderTemplate>
<ItemTemplate>
<div style="width:100%"> <asp:Label ID="lblname" runat="server" Text='<%# Eval("Patient Name") %>'></asp:Label></div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Order Number</HeaderTemplate>
<ItemTemplate>
<div style="width:100%"> <asp:Label ID="lblorder" runat="server" Text='<%# Eval("Request number") %>'></asp:Label></div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Test No.</HeaderTemplate>
<ItemTemplate>
<div style="width:100%"> <asp:Label ID="lblrepd" runat="server" Text='<%# Eval("Test Id") %>'></asp:Label></div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Test Name</HeaderTemplate>
<ItemTemplate>
<div style="width:100%"> <asp:Label ID="LblTest" runat="server" Text='<%# Eval("Test_Name") %>'></asp:Label></div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>To</HeaderTemplate>
<ItemTemplate>
<div style="width:100%"> <asp:Label ID="refhigh" runat="server" Text='<%# Eval("High Range") %>'></asp:Label></div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Text Range</HeaderTemplate>
<ItemTemplate>
<div style="width:100%"> <asp:Label ID="textrange" runat="server" Text='<%# Eval("Text Range") %>'></asp:Label></div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Request Date</HeaderTemplate>
<ItemTemplate>
<div style="width:100%"> <asp:Label ID="lblreqd" runat="server" Text='<%# Eval("Request Date") %>'></asp:Label></div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Result Date</HeaderTemplate>
<ItemTemplate>
<div style="width:100%"> <asp:Label ID="lblrepd" runat="server" Text='<%# Eval("Report Date") %>'></asp:Label></div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
/>
</asp:GridView>
</div>
So, I am creating a basic CRUD system, where you can register clients, and I want to make every textbox a required field, but I don't know how to do that.
Can someone help me ?
My code :
<asp:BoundField DataField="cliente_id" HeaderText="Id do Cliente" ReadOnly="true" />
<asp:TemplateField HeaderText="Nome do Cliente">
<ItemTemplate>
<asp:Label ID="lblClienteNome" runat="server" Text='<%# Eval("cliente_nome")%>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtclienteNome" runat="server" Text='<%# Eval("cliente_nome")%>'/>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtbnome" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "E-mail do Cliente">
<ItemTemplate>
<asp:Label ID="lblClienteEmail" runat="server" Text='<%# Eval("cliente_email")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtclienteEmail" runat="server" Text='<%# Eval("cliente_email")%>'/>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtbemail" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Data de Nascimento">
<ItemTemplate>
<asp:Label ID="lbldataNascimento" runat="server" Text='<%# Eval("cliente_dataNascimento")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtdataNascimento" runat="server" Text='<%# Eval("cliente_dataNascimento")%>'/>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtbdataNascimento" runat="server" />
<asp:LinkButton ID="btnAdd" CommandName="AddNew" runat="server" CssClass="btn btn-large btn-info pull-right"><i class="glyphicon glyphicon-plus"></i> Adicionar</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" ShowDeleteButton="true" />
</Columns>
Simple way to do is using adding the following code under all the textbox
<asp:RequiredFieldValidator runat="server" id="reqName" controltovalidate="textboxid" errormessage="Please enter your Value!" />
I tried with this but it's not working:
function validationsBirdstra() {
var grid = document.getElementById('<%=GVBirdstransfer.ClientID%>');
var theTextBoxvalue = grid.rows[0].cells[1].children[0].value;
if (theTextBoxvalue == "") {
alert('enter Type please');
return false;
}
}
and my gridview is
<table style="clear: both; float: none; margin-right: auto; margin-left: auto; font: 13px Verdana;">
<tbody>
<tr>
<td>
<asp:GridView ID="GVBirdstransfer" runat="server" BorderColor="#BDBDBD" ShowFooter="True"
CssClass="center" OnRowDataBound="GVBirdstransfer_RowDataBound" GridLines="Horizontal"
OnRowDeleting="GVBirdstransfer_RowDeleting" AutoGenerateColumns="False">
<EmptyDataTemplate>
No Records found</EmptyDataTemplate>
<Columns>
<asp:TemplateField ItemStyle-Width="20px" HeaderText="SNo">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
<ItemStyle Width="20px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Type">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:DropDownList ID="ddltype" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddltype_SelectedIndexChanged">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RFVbirdtype" runat="server" ControlToValidate="ddltype"
ValidationGroup="GridView1" InitialValue="Select Me" Display="Dynamic" ErrorMessage="Please select Type"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="VCEbirdtype" runat="Server" TargetControlID="RFVbirdtype"
EnableViewState="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="To Branch">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:DropDownList ID="ddltobranch" runat="server" AutoPostBack="true">
<asp:ListItem Value="0" Text="--Select--"></asp:ListItem>
</asp:DropDownList>
<%--<asp:RequiredFieldValidator ID="RFVfrmbranch" runat="server" ControlToValidate="ddltobranch"
ValidationGroup="GridView1" InitialValue="0" Display="None" ErrorMessage="Please select Branch "></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="VCEfrmbranch" runat="Server" TargetControlID="RFVfrmbranch"
EnableViewState="false" />--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Birds">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="txtbirds" Width="70px" MaxLength="15" runat="server" onkeypress="return validatenumerics(event)"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv" runat="server" ControlToValidate="txtbirds"
ValidationGroup="GridView1" Display="Static" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mortality">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="txtmortality" Width="70px" MaxLength="15" runat="server" onkeypress="return validatenumerics(event)"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv1" runat="server" ControlToValidate="txtmortality"
ValidationGroup="GridView1" Display="Static" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Weight">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="txtweight" Width="70px" MaxLength="15" runat="server" onkeypress="return validatenumerics(event)"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv2" runat="server" ControlToValidate="txtweight"
ValidationGroup="GridView1" Display="Static" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="GRNo">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="txtgrno" Width="70px" MaxLength="15" runat="server" AutoPostBack="true"
onkeypress="return validatenumerics(event)"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv3" runat="server" ControlToValidate="txtgrno"
ValidationGroup="GridView1" Display="Static" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:Button ID="BtnAdd" runat="server" Text="Add" OnClick="BtnAdd_Click" ValidationGroup="GridView1"
CausesValidation="true" />
</FooterTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
</td>
</tr>
<%-- <tr>
<td align="center" style="padding-right: 10px">
<b>Total Weight:</b>
<asp:TextBox ID="txtTotal1" runat="server" Width="80px" />
</td>
</tr>--%>
<tr>
<td align="center">
<asp:Button ID="btnsave" runat="server" Text="Save" OnClick="btnSave_Click" OnClientClick="return validationsBirdstra();"
ValidationGroup="GridView1" CausesValidation="true" Style="height: 26px" />
</td>
</tr>
</tbody>
</table>
I had created gridview. In that I have some dropdownlists and some textboxes. Now I want to put validations for those.
If you are using RequiredFieldValidator then why are you going for Javascript. Just Remove OnClientClick in Button and try, It will fire.
And Set Display as Dynamic in RequiredFieldValidator
Try this
<table style="clear: both; float: none; margin-right: auto; margin-left: auto; font: 13px Verdana;">
<tbody>
<tr>
<td>
<asp:GridView ID="GVBirdstransfer" runat="server" BorderColor="#BDBDBD" ShowFooter="True"
CssClass="center" OnRowDataBound="GVBirdstransfer_RowDataBound" GridLines="Horizontal"
OnRowDeleting="GVBirdstransfer_RowDeleting" AutoGenerateColumns="False">
<EmptyDataTemplate>
No Records found</EmptyDataTemplate>
<Columns>
<asp:TemplateField ItemStyle-Width="20px" HeaderText="SNo">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
<ItemStyle Width="20px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Type">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:DropDownList ID="ddltype" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddltype_SelectedIndexChanged">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RFVbirdtype" runat="server" ControlToValidate="ddltype"
ValidationGroup="GridView1" InitialValue="Select Me" Display="Dynamic" ErrorMessage="Please select Type"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="VCEbirdtype" runat="Server" TargetControlID="RFVbirdtype"
EnableViewState="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="To Branch">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:DropDownList ID="ddltobranch" runat="server" AutoPostBack="true">
<asp:ListItem Value="0" Text="--Select--"></asp:ListItem>
</asp:DropDownList>
<%--<asp:RequiredFieldValidator ID="RFVfrmbranch" runat="server" ControlToValidate="ddltobranch"
ValidationGroup="GridView1" InitialValue="0" Display="None" ErrorMessage="Please select Branch "></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="VCEfrmbranch" runat="Server" TargetControlID="RFVfrmbranch"
EnableViewState="false" />--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Birds">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="txtbirds" Width="70px" MaxLength="15" runat="server" onkeypress="return validatenumerics(event)"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv" runat="server" ControlToValidate="txtbirds"
ValidationGroup="GridView1" Display="Dynamic" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mortality">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="txtmortality" Width="70px" MaxLength="15" runat="server" onkeypress="return validatenumerics(event)"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv1" runat="server" ControlToValidate="txtmortality"
ValidationGroup="GridView1" Display="Dynamic" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Weight">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="txtweight" Width="70px" MaxLength="15" runat="server" onkeypress="return validatenumerics(event)"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv2" runat="server" ControlToValidate="txtweight"
ValidationGroup="GridView1" Display="Dynamic" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="GRNo">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="txtgrno" Width="70px" MaxLength="15" runat="server" AutoPostBack="true"
onkeypress="return validatenumerics(event)"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv3" runat="server" ControlToValidate="txtgrno"
ValidationGroup="GridView1" Display="Dynamic" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:Button ID="BtnAdd" runat="server" Text="Add" OnClick="BtnAdd_Click" ValidationGroup="GridView1"
CausesValidation="true" />
</FooterTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
</td>
</tr>
<%-- <tr>
<td align="center" style="padding-right: 10px">
<b>Total Weight:</b>
<asp:TextBox ID="txtTotal1" runat="server" Width="80px" />
</td>
</tr>--%>
<tr>
<td align="center">
<asp:Button ID="btnsave" runat="server" Text="Save" OnClick="btnSave_Click" ValidationGroup="GridView1" CausesValidation="true" Style="height: 26px" />
</td>
</tr>
</tbody>
</table>
After browsing your web open the page source and look for the grid view.
you will get the client id there.now replace the <%=GVBirdstransfer.ClientID%> with your client id and check
I have multiple gridviews on one page. For each gridview, there are two ways to insert a new record. One is through FooterTemplate of a TemplateField when the gridview has data and the other through EmptyDataTemplate when the gridview is empty.
By itself, the inserts work well. However, if another gridview is empty, then by default, the insert portion in its EmptyDataTemplate is displayed. When this is displayed, I can't get the FooterTemplate of another gridview to display. That portion is inaccessible until I get rid of the EmptyDataTemplate by forcing an insert.
<asp:Button ID="btnAddNewDomSoilType" runat="server" Text="Add new record" CssClass="btnNewRecord" OnClick="addNewDomSoilType" />
<asp:GridView ID="gvDomSoilType" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataSourceID="dsDomSoilType" CssClass="data"
AllowSorting="True" onrowcommand="gvDomSoilType_RowCommand" DataKeyNames="HabitatObsSubstrateID, HabitatObservationID, SubstrateID" >
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete"
OnClientClick="return confirm('Are you sure?');"
AlternateText="Delete" ForeColor="Blue"></asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnInsertSubmit" runat="server" Text="Submit" CommandName="SubmitInsert" CssClass="btnInsertSEID" />
<asp:Button ID="btnInsertCancel" runat="server" Text="Cancel" CommandName="CancelInsert" CssClass="btnInsertSEID" CausesValidation="false" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Substrate" SortExpression="Substrate">
<FooterTemplate>
<asp:DropDownList ID="ddlSoilType" runat="server"
DataSourceID="dsDomSoilType_Insert" DataTextField="Description"
DataValueField="Value" AppendDataBoundItems="true">
<asp:ListItem Text="" Value="" Selected="True"></asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Substrate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<asp:Label ID="Label4" runat="server" Text="Substrate: " CssClass="insertLabel"></asp:Label>
<asp:DropDownList ID="ddlSoilType2" runat="server"
DataSourceID="dsDomSoilType_Insert" DataTextField="Description"
DataValueField="Value" AppendDataBoundItems="true">
<asp:ListItem Text="" Value="" Selected="True"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnInsertEmpty" runat="Server" Text="Insert" CommandName="EmptyInsert" UseSubmitBehavior="False" />
</EmptyDataTemplate>
</asp:GridView>
<asp:Button ID="btnAddNewVegCover" runat="server" Text="Add new record" CssClass="btnNewRecord" OnClick="addNewVegCover" />
<asp:GridView ID="gvVegCover" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataSourceID="dsVegCover" CssClass="data"
AllowSorting="True" onrowcommand="gvVegCover_RowCommand" DataKeyNames="HabitatObsVegID">
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete"
OnClientClick="return confirm('Are you sure?');"
AlternateText="Delete" ForeColor="Blue"></asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnInsertSubmit" runat="server" Text="Submit" CommandName="SubmitInsert" CssClass="btnInsertSEID" />
<asp:Button ID="btnInsertCancel" runat="server" Text="Cancel" CommandName="CancelInsert" CssClass="btnInsertSEID" CausesValidation="false" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="HabitatVegetationType" SortExpression="HabitatVegetationType">
<FooterTemplate>
<asp:DropDownList ID="ddlVegType" runat="server"
DataSourceID="dsVegType_Insert" DataTextField="Description"
DataValueField="Value" AppendDataBoundItems="true">
<asp:ListItem Text="" Value="" Selected="True"></asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblVegType" runat="server" Text='<%# Bind("HabitatVegetationType") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="VegetationTypePercent" SortExpression="VegetationTypePercent">
<FooterTemplate>
<asp:TextBox ID="txtVegTypePercent" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblVegTypePercentage" runat="server" Text='<%# Bind("VegetationTypePercent") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<asp:Label ID="Label2" runat="server" Text="Vegetation Type:" CssClass="insertLabel"></asp:Label>
<asp:DropDownList ID="ddlVegType2" runat="server"
DataSourceID="dsVegType_Insert" DataTextField="Description"
DataValueField="Value" AppendDataBoundItems="true">
<asp:ListItem Text="" Value="" Selected="True"></asp:ListItem>
</asp:DropDownList>
<asp:Label ID="Label5" runat="server" Text="Percenttage:" CssClass="insertLabel"></asp:Label>
<asp:TextBox ID="txtVegTypePercent2" runat="server"></asp:TextBox>
<asp:Button ID="btnInsertEmpty" runat="Server" Text="Insert" CommandName="EmptyInsert" UseSubmitBehavior="False" />
</EmptyDataTemplate>
</asp:GridView>
Code behind:
protected void addNewDomSoilType(object sender, EventArgs e)
{
gvDomSoilType.ShowFooter = true;
}
protected void addNewVegCover(object sender, EventArgs e)
{
gvVegCover.ShowFooter = true;
}
I know my explanation is a bit confusing. Let me know what doesn't make sense and I'll try to clarify. Thanks for looking.
These two gridviews shouldn't impact each other. I think it might be the PostBack that is messing up the state of the webpage. On the PageLoad do Page.IsPostBack false and then populate the data. Make sure the events are hooked up to the right GridView.
This UpdatePanel is contained by an UserControl. When the LinkButton is pressed arow should be added in another GridView. When an user is logged in this control is working well.
The problems appears when an user is not logged in and try to push that button. No event triggers.
Someone suggested me to give a permission for accessing this control in web.config. That didn't work.
Anyone has another idea?
<asp:UpdatePanel runat="server" UpdateMode="Conditional" EnableViewState="true" ID="IngredientsUpdatePanel">
<ContentTemplate>
<asp:ObjectDataSource ID="sourceIngredients" runat="server" SelectMethod="GetAll">
</asp:ObjectDataSource>
<asp:GridView ID="Ingredients" AllowPaging="true" runat="server" DataKeyNames="IngredientId"
EnableViewState="true" DataSourceID="sourceIngredients" PageSize="5"
AutoGenerateColumns="false" HorizontalAlign="Center" OnSelectedIndexChanged="Ingredients_SelectedIndexChanged">
<RowStyle HorizontalAlign="Center" />
<HeaderStyle Font-Bold="true" ForeColor="Black" />
<Columns>
<asp:TemplateField HeaderText="Ingrediente" ItemStyle-Font-Size="10">
<ItemTemplate>
<asp:Label ID="lblId" Text='<%# Bind("IngredientId") %>' Visible="false" runat="server"/>
<asp:Label ID="lblPrice" Text='<%# Bind("Price") %>' Visible="false" runat="server"/>
<asp:Label ID="lblDescr" Text='<%# Bind("Description") %>' Visible="false" runat="server"/>
<asp:Label ID="lblName" Text='<%# Bind("Name") %>' Visible="false" runat="server"/>
<asp:Label ID="lblPict" Text='<%# Bind("Picture") %>' Visible="false" runat="server"/>
<div style="text-align:left;">
<img id="img" style="float:right;" src='<%# Eval("Picture") %>'
height="75" runat="server" alt="Picture" />
<b>
<%# Eval("Name") %>
</b>
<br />
<br />
Price: <b><%# Eval("Price") %></b>
<br />
<br />
<br />
</div>
<hr />
<div style="text-align:left;">
<b>Description</b>
</div>
<div style="width:300px;">
<%# Eval("Description") %>
</div>
<br />
<asp:LinkButton Enabled="true" runat="server" Text="Add" CommandName="Select" ID="cmdAdd" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
I solved the problem in a tricky way.
I deleted the LinkButton and before TemplateField I put a ButtonField and all is working fine.
Now the code looks like:
<Columns>
<asp:ButtonField Text="Add" CommandName="Select" />
<asp:TemplateField>
......
</asp:TemplateField>
</Columns>
Still I'm not understanding why the control had that behavior.
Don't forget to give the webresource.axd enough rights in the web.config?