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.
Related
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!" />
Dropdownlist list is not working in my following grid.I want to change label text when drop downlist changed dropdownlisth the label text is not working
<asp:TemplateField HeaderText="sup_rec_id">
<ItemTemplate>
<asp:Label runat="server" ID="lblFirstLastName" Text='<%# Eval("sup_rec_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:Label runat="server" ID="quantity" Text='<%# Eval("quantity") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Code">
<ItemTemplate>
<asp:Label runat="server" ID="code" Text='<%# Eval("code") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
AutoPostBack="true" EnableViewState="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>D</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
filename.Aspx.cs
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = "Test text";
}
Guide me what i do?
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.
Can anyone please help me to validate Textbox within Footer of the GridView Control upon Clicking the Button
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
DataKeyNames="Id" ShowFooter="true" onrowdatabound="GridView1_RowDataBound" >
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Units
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txt_Units" runat="server" Text='<%# Eval("Units") %>' ToolTip="Enter Units"></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ReadOnly="true" Text="999999" Enabled="false" ID="txt_MaxUnits" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Cost
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txt_Cost" runat="server" Text='<%# Eval("Cost") %>' ></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txt_MaxCost" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Enter Integer Between 0 to 999998" ControlToValidate="txt_Units" ValidationExpression="^(0{0,5}[1-9]|0?[1-9][0-9]|[1-9][0-9][0-9]| [1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9])$" ValidationGroup="vld_Rows"></asp:RegularExpressionValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="Enter Integer Between 0 to 999998" ControlToValidate="txt_Cost" ValidationExpression="^(0{0,5}[1-9]|0?[1-9][0-9]|[1-9][0-9][0-9]| [1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9])$" Display="Dynamic" ValidationGroup="vld_Rows"></asp:RegularExpressionValidator>
</ItemTemplate>
<FooterTemplate>
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ErrorMessage="Enter Integer Between 0 to 999998" ControlToValidate="txt_MaxCost" ValidationExpression="^(0{0,5}[1-9]|0?[1-9][0-9]|[1-9][0-9][0-9]| [1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9])$" ValidationGroup="vld_Rows1" ></asp:RegularExpressionValidator>
</FooterTemplate>
</asp:TemplateField>
<%--<asp:TemplateField>
<HeaderTemplate>
Is Max
</HeaderTemplate>
<ItemTemplate>--%>
<%-- <asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("IsMax") %>'></asp:TextBox>--%>
<%-- <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Eval("IsMax") %>' OnCheckedChanged="CheckBox1_CheckedChanged" AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateField>--%>
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" ValidationGroup="vld_Rows" />
<asp:Button ID="btn_Save" runat="server" Text="Save" onclick="btn_Save_Click" ValidationGroup="vld_Rows1" />
</ContentTemplate>
<%--<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" runat="server" />
<asp:AsyncPostBackTrigger ControlID="CheckBox1" EventName="CheckedChanged" runat="server" />
</Triggers>--%>
</asp:UpdatePanel>
Above is the Sample Code Which I have used. Upon Clicking Button(btn_Save) I need to validate the ValidateGroup with id as "vld_Rows1"
Please Suggest a Solution.
Thanks in Advance!
Put the validation control in the same template where you put your control. In your scenario, your controls are in the footer template, so you should put the validation controls in footer template, and try to use validation group as well. e.g.
<asp:TemplateField>
<ItemTemplate>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server" ValidationGroup="ft" ControlToValidate="TextBox3"
ErrorMessage="*"></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
Checkout the following MSDN article: RegularExpressionValidator Control
From the article:
If the input control is empty, no validation functions are called and
validation succeeds. Use a RequiredFieldValidator control to prevent
the user from skipping an input control.
As it states you will need to make use of a RequiredFieldValidator to ensure that data has been entered.
I have an UpdatePanel and a GridView within it. I have a problem with paging: when I press Next button, grdUsers_PageIndexChanging() is not called, so the page stays 1, and if previously I changed selection in ddlPageSize, now it goes back to the initial selection.
Also, if I am on the first page, the Previous button is not disabled, and pressing it causes Out Of Range error.
What am I doing wrong?
Thanks.
<asp:UpdatePanel ID="upnlUsers" runat="server" ChildrenAsTriggers="true" UpdateMode="Always" >
<ContentTemplate>
<div style="height:400px; width:1500px; overflow:auto;">
<asp:GridView ID="grdUsers" runat="server" AllowPaging="True" ShowHeader="false" ShowFooter="true"
AutoGenerateColumns="false" CssClass="largegridview largegridview_td"
Width="1480px" Height="100%" PageSize="100" DataKeyNames="ID" EnableSortingAndPagingCallbacks="false"
onpageindexchanging="grdUsers_PageIndexChanging"
onrowdatabound="grdUsers_RowDataBound">
<AlternatingRowStyle CssClass="alternatingrowstyle" />
<Columns>
<asp:TemplateField HeaderText="User Name" SortExpression="Name">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Name" SortExpression="LastName">
<ItemTemplate>
<asp:Label ID="lblLastName" runat="server" Text='<%# Eval("LastName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="First Name" SortExpression="FirstName">
<ItemTemplate>
<asp:Label ID="lblFirstName" runat="server" Text='<%# Eval("FirstName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email" SortExpression="Email">
<ItemTemplate>
<asp:Label ID="lblEmail" runat="server" Text='<%# Eval("Email") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="pagerstyle" />
<PagerTemplate>
<asp:Label ID="Label1" runat="server" Text="Show rows:" />
<asp:DropDownList ID="ddlPageSize" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="ddlPageSize_SelectedIndexChanged">
<asp:ListItem Value="20" />
<asp:ListItem Value="50" />
<asp:ListItem Value="100" />
</asp:DropDownList>
Page
<asp:TextBox ID="txtGoToPage" runat="server" AutoPostBack="true"
OnTextChanged="GoToPage_TextChanged" CssClass="gotopage" />
of
<asp:Label ID="lblTotalNumberOfPages" runat="server" />
<asp:Button ID="btnPrev" runat="server" CommandName="Page"
ToolTip="Previous Page" CommandArgument="Prev" CssClass="previous" />
<asp:Button ID="btnNext" runat="server" CommandName="Page" ToolTip="Next Page"
CommandArgument="Next" CssClass="next" />
</PagerTemplate>
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Agreed, I tested the code, and grdUsers_PageIndexChanging() is called on mine.
Dear Friend
their is in build paging in the gridview if you want your own paging style then you have to implement your own paging through PageDataSource Class.
Click to view code
this link provide you how to implement the paging in the Datalist and Repeater through same way you will implement the paging in grid view .
Then no pageindex change event will fired in the gridview.
I don't think you are doing anything wrong; it may not actually fire the PageIndexChanged event, it probably fires the RowCommand event. Attach to the ItemCommand event and that will receive the event.
HTH.