I have code to update a date from a sqldatasource updateCommand.
Code:
<asp:GridView ID="gdLog" runat="server" GridLines="Horizontal" CellPadding="3" CssClass="gridRows" HeaderStyle-CssClass="gridHreader" AlternatingItemStyle-CssClass="gridAlterRows" Width="100%" AutoGenerateColumns="False" AutoGenerateEditButton="True" DataKeyNames="hometemplateID" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="hometemplateID" HeaderText="hometemplateID" InsertVisible="False" ReadOnly="True" SortExpression="hometemplateID" Visible="False" />
<asp:BoundField DataField="ttitle" HeaderText="title" SortExpression="ttitle" />
<asp:TemplateField HeaderText="start">
<ItemTemplate>
<asp:Label runat="server" ID="tstart"
Text='<%# makeShortDate(DataBinder.Eval(Container.DataItem, "tstart")) %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tStartdEdit" runat="server" class="form-control calender-icon datepicker date" Text='<%# makeShortDate(DataBinder.Eval(Container.DataItem, "tstart")) %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="end">
<ItemTemplate>
<asp:Label runat="server" ID="tend"
Text='<%# makeShortDate(DataBinder.Eval(Container.DataItem, "tend")) %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tendEdit" runat="server" class="form-control calender-icon datepicker date" Text='<%# makeShortDate(DataBinder.Eval(Container.DataItem, "tend")) %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:CheckBoxField DataField="tActive" HeaderText="Active" SortExpression="tActive" />
<asp:BoundField DataField="tdatecreated" HeaderText="date added" InsertVisible="False" ReadOnly="True" SortExpression="tdatecreated" />
</Columns>
<HeaderStyle CssClass="gridHreader">
</HeaderStyle>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Dbconnection %>" SelectCommand="EXEC [usp_SelectHomePageItems] #templateid=1, #rows=1" UpdateCommand="update hometemplate set title=#ttitle, startdate=#tstart, isActive=#tActive where hometemplateID=#hometemplateID">
<UpdateParameters>
<asp:Parameter Name="tstart" />
<asp:Parameter Name="tend" />
</UpdateParameters>
</asp:SqlDataSource>
There are 2 datepickers (start and end). I need to use makeShortDate function to format the text for the datepicker(s) because when I pick from it, it seems to use the format month namespacedayspaceyear
If I don't do that, and simply use Bind("tstart") on edititemtemplate, then after I hit 'edit', it shows in the textbox as 25/7/2018 12:00:00 AM....day first for some reason, and I don't want that to confuse my customers. It's also ugly showing the 12am stuff. It also selects the wrong date when I click the calender icon, whereas if I format first, it selects the right one.
When I try my code as is, the date gets set to blank for some reason. I think I need to Bind on the edititemTemplate but as mentioned I need to format the date with the function makeShortdate.
So how do I get the textbox for the dates to be month/day/year after hit 'edit' instead of the day/month/year 12:00:00am thing? I can do it with the makeshortdate function but then the date is set to null for some reason.
Sorry about the code indent, not sure how to de-indent a block of code on here.
The datepicker is datepicker for bootstrap. In the header I use:
$(function () {
$('.datepicker').datepicker({
format: 'MM dd yyyy',
autoclose: true,
});
});
ok got it with formatting:
<asp:TemplateField HeaderText="start">
<ItemTemplate>
<asp:Label runat="server" ID="tstart" DataField="startdate"
Text='<%# DataBinder.Eval(Container.DataItem, "startdate","{0:MMM dd yyyy}") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:TextBox ID="tStartdEdit" runat="server" class="form-control calender-icon datepicker date" Text='<%# Bind("startdate","{0:MMM dd yyyy}") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
Related
I am trying to compute the column in real time meaning the calculation should be seen before an edit link is clicked. The weight first half is already found in the gridview.
The gridview is then edited to add the rating first half. the 2, weight first half and rating first half needs to be multiplied to get the result that is score first half and score first half I made it a ReadOnly.
Now I want the score first half to be saved in the SQL Server database. Mind you I already have the update command that the SqlDataSource generates.
Here is my markup:
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataKeyNames="P_C_ID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField HeaderText="P_C_ID"
InsertVisible="False" SortExpression="P_C_ID">
<EditItemTemplate>
<asp:Label ID="Label1"
runat="server"
Text='<%# Eval("P_C_ID") %>'>
</asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1"
runat="server"
Text='<%# Bind("P_C_ID") %>'>
</asp:Label>
</ItemTemplate>
<asp:TemplateField HeaderText="WEIGHT_FIRST_HALF"
SortExpression="WEIGHT_FIRST_HALF">
<EditItemTemplate>
<asp:TextBox ID="TextBox5"
runat="server"
ReadOnly="True"
Text='<%# Bind("WEIGHT_FIRST_HALF") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6"
runat="server"
Text='<%# Bind("WEIGHT_FIRST_HALF") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label9"
runat="server"
Text='<%# Bind("SCORE_FIRST_HALF") %>'>
</asp:Label>
</ItemTemplate>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:AWPConnectionString5 %>"
UpdateCommand="UPDATE [Performance_Rating_2] SET [WEIGHT FIRST HALF] = #WEIGHT_FIRST_HALF, [RATING FIRST HALF] = #RATING_FIRST_HALF, [SCORE FIRST HALF], [RATING FIRST HALF] = #RATING_FIRST_HALF = #SCORE_FIRST_HALF WHERE [P_C_ID] = #P_C_ID">
<asp:Parameter Name="WEIGHT_FIRST_HALF"
Type="Decimal" />
<UpdateParameters>
<asp:Parameter Name="RATING_FIRST_HALF"
Type="Int32" />
<asp:Parameter Name="SCORE_FIRST_HALF"
Type="Decimal" />
</UpdateParameters>
Okay folks the program is long. I just took part that is not working fine. But should you need clarity do not hesitate to ask for clarity. Right now only the weight and rating is being saved. the computed is not saved at all. I actually do not want to write it in C# codes as I need results in real time
I use EntityDataSource.
When I want to insert into the "ShiftDetails" table with the following data: (3,1,04:00:00)
It is inserted fine if I use:
<telerik:GridBoundColumn DataField="startTime" HeaderText="startTime" SortExpression="startTime"
UniqueName="startTime" DataType="System.TimeSpan" EmptyDataText="00:00:00" >
When I try this with templatefield, the startTime is 00:00:00 instead of 04:00:00
<telerik:GridTemplateColumn HeaderText="startTime" >
<ItemTemplate>
<asp:Label runat="server" ID="lblstartTime" Text='<%# Eval("startTime")%>'></asp:Label>
</ItemTemplate>
<InsertItemTemplate>
<telerik:RadDateInput ID="txt_startTime" runat="server" DbSelectedDate='<%# Eval("startTime","{0:hh\\:mm\\:ss}") %>' DateFormat="HH:mm:ss" DisplayDateFormat="HH:mm:ss"
Culture="English (United States)" LabelWidth="64px"
Width="160px" Height="20px" EmptyMessage="!">
<EmptyMessageStyle ForeColor="Red" />
</telerik:RadDateInput>
</InsertItemTemplate>
<EditItemTemplate>
<telerik:RadDateInput ID="txt_startTime" runat="server" DateFormat="HH:mm:ss" DisplayDateFormat="HH:mm:ss"
Culture="English (United States)" LabelWidth="64px"
Width="160px" Height="20px" EmptyMessage="!">
<EmptyMessageStyle ForeColor="Red" />
</telerik:RadDateInput>
</EditItemTemplate>
</telerik:GridTemplateColumn>
My rad grid is master-details
the source of the details :
<ef:EntityDataSource ID="GetSourceDetail" runat="server" ContextTypeName="ResidenceShift.RShiftEntities" EntitySetName="ShiftDetails" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" ConnectionString="name=RShiftEntities" DefaultContainerName="RShiftEntities" AutoGenerateWhereClause="True" Include="ResidenceShift,ShiftType" AutoPage="False" AutoSort="False" EntityTypeFilter="" Select="" Where="" >
<WhereParameters>
<asp:SessionParameter DefaultValue="0" Name="shiftId" SessionField="shiftId" DbType="Int32" />
</WhereParameters>
</ef:EntityDataSource>
Why does it work fine with the bound field and then fails with the template field?!
Try using RadDateTimePicker instead, as it should also submit the time.
I have a grid view in my aspx page. I have enabled paging also.
Paging is working fine when an ajax control is in page, but when I removed the ajax control paging is not working anymore. ie, on clicking page number 2 grid becomes empty.
What could be the possible reason? Please suggest a solution.
code
<asp:GridView ID="SitesGrid" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="SitesDataMgr" AutoGenerateColumns="False" DataKeyNames="ID" CellPadding="3" CellSpacing="3" OnRowDataBound="viewSite_RowDataBound" class="tbl_blck gridtable clearfix" PageSize="4" EmptyDataText="No rows found">
<Columns>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="clientID" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" HeaderStyle-ForeColor="White" SortExpression="ClientName">
<ItemTemplate>
<asp:Label ID="clientLabel" runat="server" Text='<%# Bind("ClientName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status" HeaderStyle-ForeColor="White" SortExpression="SiteStatus">
<ItemTemplate>
<asp:Label ID="siteLabel" runat="server" Text='<%# Bind("SiteStatus") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Details" HeaderStyle-ForeColor="White" >
<ItemTemplate>
<asp:LinkButton ID="viewSite" runat="server" OnClick="viewSite_click" CausesValidation="False" CommandName="Edit"
Text="View"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="SitesDataMgr" runat="server" ConvertNullToDBNull="True" OldValuesParameterFormatString="{0}" SelectMethod="GetAllSitesByUser" FilterExpression="ClientName LIKE '%{0}%'" TypeName="Creation.DataMgr">
<SelectParameters>
<asp:SessionParameter Name="createdUserID" Type="String" SessionField="strUserName" />
</SelectParameters>
<FilterParameters>
<asp:ControlParameter Name="ClientName" ControlID="txtSearch" PropertyName="Text" />
</FilterParameters>
</asp:ObjectDataSource>
It looks like you have not added the SelectCount method to your ObjectDataSource.
This is required for the ObjectDatasource to correctly page your data.
Your select method needs the int parameters maximumRows and startRowIndex This is the default parameter names required for paging. if you do have them in. Please use them to filter your data.
<telerik:GridTemplateColumn HeaderText="Code" SortExpression="Code" UniqueName="Code" AllowFiltering="True">
<ItemTemplate>
<asp:LinkButton ID="lbCCode" runat="server" Text='<%# Eval("Code") %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
So how can I allow RadGrid to filter the results based on the text value of LinkButton? Is there a way to do that?
Please try with the below code snippet.
<telerik:GridTemplateColumn HeaderText="Code" SortExpression="Code" UniqueName="Code" AllowFiltering="True"
DataField="Code">
<ItemTemplate>
<asp:LinkButton ID="lbCCode" runat="server" Text='<%# Eval("Code") %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
I have added DataField property in template column. if you get any error in grid then please set EnableLinqExpressions="false" in your grid.
So i got this gridview on ASP.NET, it is about a gmail client, i made a template field with a check box that is for select several message at the same time, but first when you select a message i want to change the row background color, I already have my CSS but i dont know how to trigger the action or how to know what row was selected in the code. Here is the template of my grid:
<asp:GridView ID="inboxGrid" runat="server"
AutoGenerateColumns="false" CssClass="inbox" ShowHeader="false" BorderStyle="None" GridLines="None">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
<ItemStyle Width="24" CssClass="check"/>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle CssClass="from" />
<ItemTemplate>
<asp:Label ID="lblFrom" runat="server"
Text = '<%# Eval("From") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle CssClass="subject" />
<ItemTemplate>
<asp:Label ID="lblSubject" runat="server" Text='<%# Eval("Subject") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle CssClass="date" />
<ItemTemplate>
<asp:Label ID="lblFecha" runat="server" Text='<%# Eval("Fecha") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle CssClass="inbox"/>
</asp:GridView>
Here is a solution using JQuery
Provided you add a CssClass named chk to asp:checkbox
<asp:CheckBox ID="chkSelect" runat="server" CssClass="chk" />
Here is the script
$(document).ready(function () {
$(".chk :checkbox").live("click", function () {
$(this).closest("tr").css("background-color", this.checked ? "#0000FF" : "");
});
});
Try this:
<asp:CheckBox ID="chkSelect" runat="server" OnClick="changeCss(this.id);" />
You can use toggleClass('CssClassName') to toggle the class on checkbox clicks:
function changeCss(ctrlId){
$(ctrlId).parent().parent().toggleClass('check');
}
The hierarchy is tr > td > checkbox, we go reverse to change the css of tr/row.