Hi All!
I have a radgrid that uses a SQL database for its datasource. The fields are of type "date" so there are no times in the database fields. However, my radgrid adds 12:00:00 AM to all of its times. I have attempted DateFormatString = "{0:MM/dd/yy}" or "{0,d}" but neither seem to work. Any thoughts?
Thanks,
Mark
I have a radgrid that uses a SQL database for its datasource. The fields are of type "date" so there are no times in the database fields. However, my radgrid adds 12:00:00 AM to all of its times. I have attempted DateFormatString = "{0:MM/dd/yy}" or "{0,d}" but neither seem to work. Any thoughts?
Thanks,
Mark
12 Answers, 1 is accepted
0
Mark
Top achievements
Rank 1
answered on 24 Sep 2013, 09:16 PM
I've also noticed that the GridDateTimeColumn appears to be very compacted/scrunched-up. I have attempted to set the FilterControlWidth, but it does not appear to be changing the column width . . .
All the columns look fine.
All the columns look fine.
0
Princy
Top achievements
Rank 2
answered on 25 Sep 2013, 03:55 AM
Hi Mark,
Please try the below code snippet,it works fine at my end.If this doesn't help,please provide your code.
To get only the date of a GridDateTimeColumn please try,
ASPX:
To set the Filter Control Width, please try the following,
C#:
Thanks,
Princy
Please try the below code snippet,it works fine at my end.If this doesn't help,please provide your code.
To get only the date of a GridDateTimeColumn please try,
ASPX:
<telerik:GridDateTimeColumn DataField="OrderDate" HeaderText="OrderDate" UniqueName="OrderDate" DataType="System.DateTime" DataFormatString="{0:MM/dd/yy}"></telerik:GridDateTimeColumn>To set the Filter Control Width, please try the following,
C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) { if (e.Item is GridFilteringItem) { GridFilteringItem filterItem = (GridFilteringItem)e.Item; ((RadDatePicker)filterItem["OrderDate"].Controls[0]).Width = Unit.Pixel(70); } }Thanks,
Princy
0
Mark
Top achievements
Rank 1
answered on 25 Sep 2013, 07:41 PM
Princy,
Thanks for the reply!
Unfortunately, I'm doing everything in code behind. The width change was identical to the one you posted, but it doesn't seem to work. I have a mix of other gridboundcolumns in the grid as well. The datetime column is as follows:
I have also tried the following to fix the width problem:
Thanks,
Mark
Thanks for the reply!
Unfortunately, I'm doing everything in code behind. The width change was identical to the one you posted, but it doesn't seem to work. I have a mix of other gridboundcolumns in the grid as well. The datetime column is as follows:
GridDateTimeColumn dateColumn = new GridDateTimeColumn();dateColumn.DataField = "OrderDate";dateColumn.HeaderText = "OrderDate";dateColumn.UniqueName = "OrderDate";dateColumn.DataFormatString = "{0:MM/dd/yy}";I have also tried the following to fix the width problem:
dateColumn.HeaderStyle.Width = Unit.Pixel(300);dateColumn.FilterControlWidth = Unit.Pixel(300);Thanks,
Mark
0
Princy
Top achievements
Rank 2
answered on 26 Sep 2013, 05:11 AM
Hi Mark,
I have tried your code and its working fine at my end.Make sure you haven't set any other styling to grid.Please provide your full code snippet.Below is the code i tried,can you try that and check if the issue exist.
ASPX:
C#:
Thanks,
Princy
I have tried your code and its working fine at my end.Make sure you haven't set any other styling to grid.Please provide your full code snippet.Below is the code i tried,can you try that and check if the issue exist.
ASPX:
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ConnectionStrings:Northwind_newConnectionString3 %>" SelectCommand="SELECT * FROM [Orders]"></asp:SqlDataSource>C#:
protected void Page_Init(object sender, System.EventArgs e) { DefineGridStructure(); } private void DefineGridStructure() { RadGrid grid = new RadGrid(); grid.ID = "RadGrid1"; grid.DataSourceID = "SqlDataSource1"; grid.Skin = "Vista"; grid.Width = Unit.Percentage(100); grid.PageSize = 15; grid.AllowPaging = true; grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric; grid.AutoGenerateColumns = false; grid.AllowFilteringByColumn = true; grid.MasterTableView.Width = Unit.Percentage(100); grid.MasterTableView.DataKeyNames = new string[] { "OrderID" }; GridBoundColumn boundColumn = new GridBoundColumn(); grid.MasterTableView.Columns.Add(boundColumn); boundColumn.DataField = "OrderID"; boundColumn.HeaderText = "OrderID"; boundColumn = new GridBoundColumn(); grid.MasterTableView.Columns.Add(boundColumn); boundColumn.DataField = "ShipCity"; boundColumn.HeaderText = "ShipCity"; GridDateTimeColumn date = new GridDateTimeColumn(); grid.MasterTableView.Columns.Add(date); date.DataField = "OrderDate"; date.HeaderText = "OrderDate"; date.UniqueName = "OrderDate"; date.DataFormatString = "{0:MM/dd/yy}"; date.DataType = typeof(System.DateTime); date.HeaderStyle.Width = Unit.Pixel(200); date.FilterControlWidth = Unit.Pixel(200); this.PlaceHolder1.Controls.Add(grid); }Thanks,
Princy
0
Qwicksoft
Top achievements
Rank 1
answered on 11 Jan 2014, 11:22 AM
Hi Princy,
i have to update a variable while click on radiobutton columntype in radgrid.Which event will be use?
i have to update a variable while click on radiobutton columntype in radgrid.Which event will be use?
0
Princy
Top achievements
Rank 2
answered on 15 Jan 2014, 06:33 AM
Hi,
I'm not clear about your requirement, I guess you have a RadioButtonList in your TemplateColumn and on its OnSelectedIndexChanged you want to change the text of any other column. Please try the following code snippet. If this doesn't help, please elaborate on your required scenario and provide code if necessary.
ASPX:
C#:
Thanks,
Princy
I'm not clear about your requirement, I guess you have a RadioButtonList in your TemplateColumn and on its OnSelectedIndexChanged you want to change the text of any other column. Please try the following code snippet. If this doesn't help, please elaborate on your required scenario and provide code if necessary.
ASPX:
<Columns> <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn> <ItemTemplate> <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"> <asp:ListItem Text="Check"></asp:ListItem> <asp:ListItem Text="Uncheck"></asp:ListItem> </asp:RadioButtonList> </ItemTemplate> </telerik:GridTemplateColumn></Columns>C#:
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e){ RadioButtonList check = (RadioButtonList)sender; GridDataItem item = (GridDataItem)check.NamingContainer; if (check.SelectedItem.Text == "Check") { item["OrderID"].Text = "Checked"; //Accessing BoundColumn } else { item["OrderID"].Text = "Unchecked"; }}Thanks,
Princy
0
Qwicksoft
Top achievements
Rank 1
answered on 20 Jan 2014, 09:23 AM
Hi princy,
How to set radio button in rad GridTemplateColumn????
Not radiobutton list,
i used this,
<rad:GridTemplateColumn AllowFiltering="false">
<ItemTemplate>
<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadioButton_SelectedIndexChanged">
</asp:RadioButton>
</ItemTemplate>
</rad:GridTemplateColumn>
but if i select radio button select all radio buttons.i need select only one radio button,that row only select.
How to set radio button in rad GridTemplateColumn????
Not radiobutton list,
i used this,
<rad:GridTemplateColumn AllowFiltering="false">
<ItemTemplate>
<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadioButton_SelectedIndexChanged">
</asp:RadioButton>
</ItemTemplate>
</rad:GridTemplateColumn>
but if i select radio button select all radio buttons.i need select only one radio button,that row only select.
0
Princy
Top achievements
Rank 2
answered on 20 Jan 2014, 10:00 AM
Hi,
Please try the following code snippet to access RadioButton:
ASPX:
C#:
Thanks,
Princy
Please try the following code snippet to access RadioButton:
ASPX:
<MasterTableView DataKeyNames="ID"> <Columns> <telerik:GridTemplateColumn> <ItemTemplate> <asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="true" OnCheckedChanged="RadioButton1_CheckedChanged" /> </ItemTemplate> </telerik:GridTemplateColumn> </Columns></MasterTableView>C#:
protected void RadioButton1_CheckedChanged(object sender, EventArgs e){ RadioButton radbtn = (RadioButton)sender; GridDataItem data = (GridDataItem)radbtn.NamingContainer; if (radbtn.Checked) { string ID = data.GetDataKeyValue("ID").ToString();//Access DataKey value of selected row }}Thanks,
Princy
0
Qwicksoft
Top achievements
Rank 1
answered on 20 Jan 2014, 10:12 AM
hi princy,
i tried this,but i have select only one row one time.if i select next row that ll not select ...
<script type="text/javascript" language="javascript">
function OnRadioClick(rb) {
var grid = $find("<%=ToolBarcodeGrid.ClientID %>");
var element = grid.get_element();
var rbs = element.getElementsByTagName("input");
for (var i = 0; i < rbs.length; i++) {
if (rbs[i].type == "radio") {
if (rbs[i].checked && rbs[i] != rb) {
rbs[i].checked = false;
break;
}
}
}
}
</script>
i tried this,its wrkin...but checked change is not working
<MasterTableViewDataKeyNames="ID" > <Columns> <telerik:GridTemplateColumn > <ItemTemplate> <asp:RadioButton ID="RadioButton1"runat ="server"AutoPostBack="true" OnCheckedChanged="RadioButton1_CheckedChanged" /> </ItemTemplate> </telerik:GridTemplateColumn > </Columns></MasterTableView>i tried this,but i have select only one row one time.if i select next row that ll not select ...
<script type="text/javascript" language="javascript">
function OnRadioClick(rb) {
var grid = $find("<%=ToolBarcodeGrid.ClientID %>");
var element = grid.get_element();
var rbs = element.getElementsByTagName("input");
for (var i = 0; i < rbs.length; i++) {
if (rbs[i].type == "radio") {
if (rbs[i].checked && rbs[i] != rb) {
rbs[i].checked = false;
break;
}
}
}
}
</script>
i tried this,its wrkin...but checked change is not working
0
Princy
Top achievements
Rank 2
answered on 21 Jan 2014, 05:03 AM
Hi,
I'm not sure about your issue, but the code is working fine at my end. I guess you want only single row to be selected and you want to access the selected row. Here is a sample i tried:
ASPX:
C#:
JS:
Thanks,
Princy
I'm not sure about your issue, but the code is working fine at my end. I guess you want only single row to be selected and you want to access the selected row. Here is a sample i tried:
ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" AllowPaging="true" OnNeedDataSource="RadGrid1_NeedDataSource"> <MasterTableView DataKeyNames="ID"> <Columns> <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID" /> <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name" /> <telerik:GridTemplateColumn UniqueName="Number" DataField="Number" HeaderText="Number"> <ItemTemplate> <%#Eval("Number")%> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn HeaderText="Check"> <ItemTemplate> <asp:RadioButton ID="RadioButton1" runat="server" onclick="OnRadioClick(this);" Text="Check" AutoPostBack="true" OnCheckedChanged="RadioButton1_CheckedChanged" /> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView></telerik:RadGrid>C#:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e){ dynamic data = new[] { new { ID = 1, Name = "Name1", Number=123}, new { ID = 2, Name = "Name2", Number=234}, new { ID = 3, Name = "Name3", Number=234}, new { ID = 4, Name = "Name4", Number=456}, new { ID = 5, Name = "Name5", Number=567}, new { ID = 6, Name = "Name6", Number=567}, new { ID = 7, Name = "Name7", Number=789}, new { ID = 8, Name = "Name8", Number=896}, new { ID = 9, Name = "Name9", Number=741}}; RadGrid1.DataSource = data;}protected void RadioButton1_CheckedChanged(object sender, EventArgs e){ RadioButton radbtn = (RadioButton)sender; GridDataItem data = (GridDataItem)radbtn.NamingContainer; ((sender as RadioButton).Parent.Parent as GridItem).Selected = (sender as RadioButton).Checked; // Select the row if (radbtn.Checked) { string ID = data.GetDataKeyValue("ID").ToString();//Access DataKey value of selected row }}JS:
<script type="text/javascript" language="javascript"> function OnRadioClick(rb) { var grid = $find("<%=RadGrid1.ClientID %>"); var element = grid.get_element(); var rbs = element.getElementsByTagName("input"); for (var i = 0; i < rbs.length; i++) { if (rbs[i].type == "radio") { if (rbs[i].checked && rbs[i] != rb) { rbs[i].checked = false; break; } } } }</script>Thanks,
Princy
0
Qwicksoft
Top achievements
Rank 1
answered on 19 May 2014, 12:17 PM
Hi Princy,
How to Create a Line Chart with Below Data table. Count in Y-axis and Month in X-axis.and for each student i need a Line series.
Count Student name Month
1 AAAA April
1 BBBB April
8 BBBB March
60 AAAA March
4 EEEE May
How to Create a Line Chart with Below Data table. Count in Y-axis and Month in X-axis.and for each student i need a Line series.
Count Student name Month
1 AAAA April
1 BBBB April
8 BBBB March
60 AAAA March
4 EEEE May
0
Hello Aruna,
I would suggest that you open a new forum thread or a formal support ticket and choose the corresponding product category for it. That way you will get a more accurate response.
Regards,
Eyup
Telerik
I would suggest that you open a new forum thread or a formal support ticket and choose the corresponding product category for it. That way you will get a more accurate response.
Regards,
Eyup
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
