Hello everybody i am a little bit stuck and unable to figure aout the problem i am having.... my buttun in bellow form doesn't do anything, this example is guided from http://demos.telerik.com/aspnet-ajax/editor/examples/saveindatabase/defaultcs.aspx only differnce is that i use sql database, here is my example:
this is cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Telerik.Web.UI;
public partial class editVijesti_vijesti : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ReadAllRecords();
}
}
public void btnSpremi_Click(object sender, EventArgs e)
{
SqlConnection connection = CreateConnection();
SqlCommand command= null;
if (uredeneVijesti.Value != string.Empty)
{
command = new SqlCommand("UPDATE Vijesti SET Datum = Now(), TijeloVijesti = @content WHERE vijestiID= @nid", connection);
command.Parameters.AddWithValue("content", EditorVijesti.Content);
command.Parameters.AddWithValue("nid", Convert.ToInt32(uredeneVijesti.Value));
}
else
{
command = new SqlCommand("INSERT INTO Vijesti (Datum, TijeloVijesti) VALUES (Now(), @content)", connection);
command.Parameters.AddWithValue("content", EditorVijesti.Content);
}
try
{
command.ExecuteNonQuery();
}
catch (Exception)
{ }
connection.Close();
this.Response.Redirect(this.Request.Url.PathAndQuery);
}
protected SqlConnection CreateConnection()
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = "Data Source=mssql3.mojsite.com,1555;Initial Catalog=iskratrade_hai;Persist Security Info=True;User ID=iskratrade_hai;Password=091011br"; connection.Open();
return connection;
}
protected void gridVijesti_ItemCommand(object sender, DataGridCommandEventArgs args)
{
SqlConnection connection = CreateConnection();
if (args.CommandName == "Delete")
{
SqlCommand com = new SqlCommand("DELETE FROM Vijesti WHERE vijestiID =@nid", connection);
com.Parameters.AddWithValue("nid", args.Item.Cells[0].Text);
com.ExecuteNonQuery();
connection.Close();
}
else if (args.CommandName == "Edit")
{
SqlCommand command = new SqlCommand("SELECT TijeloVijesti FROM Vijesti WHERE vijestiID= @nid", connection);
command.Parameters.AddWithValue("nid", args.Item.Cells[0].Text);
SqlDataReader record = command.ExecuteReader();
if (record.Read())
{
EditorVijesti.Content = record.GetString(0);
uredeneVijesti.Value = args.Item.Cells[0].Text;
}
else
{
EditorVijesti.Content = "";
uredeneVijesti.Value = "";
}
record.Close();
}
connection.Close();
ReadAllRecords();
}
private void ReadAllRecords()
{
SqlConnection connection = CreateConnection();
SqlCommand command2 = new SqlCommand("SELECT vijestiID, Datum, TijeloVijesti FROM Vijesti", connection);
gridVijesti.DataSource = command2.ExecuteReader();
gridVijesti.DataBind();
connection.Close();
}
}
and this is aspx page:
<asp:ScriptManager ID="scriptmanager" runat="server"/>
<div>
<input type="hidden" name="uredeneVijesti" runat="server" id="uredeneVijesti" />
<telerik:RadEditor ID="EditorVijesti" runat="server" SkinID="DefaultSetOfTools"
height="500px" Width="800px">
<Modules>
<telerik:EditorModule Name="RadEditorStatistics" Visible="false" Enabled="true" />
<telerik:EditorModule Name="RadEditorDomInspector" Visible="false" Enabled="true" />
<telerik:EditorModule Name="RadEditorNodeInspector" Visible="false" Enabled="true" />
<telerik:EditorModule Name="RadEditorHtmlInspector" Visible="false" Enabled="true" />
</Modules>
<ImageManager ViewPaths="~/editVijesti" UploadPaths="~/editVijesti/slike/novo" DeletePaths="~/editVijesti/slike/obrisano" />
<FlashManager DeletePaths="editVijesti/slike/obrisano" UploadPaths="~/editVijesti/slike/novo" ViewPaths="~/editVijesti/slike" />
<DocumentManager DeletePaths="editVijesti/slike/obrisano" UploadPaths="~/editVijesti/slike/novo" ViewPaths="~/editVijesti/slike" />
<MediaManager DeletePaths="editVijesti/slike/obrisano" UploadPaths="~/editVijesti/slike/novo" ViewPaths="~/editVijesti/slike" />
<TemplateManager DeletePaths="editVijesti/slike/obrisano" UploadPaths="~/editVijesti/slike/novo" ViewPaths="~/editVijesti/slike" />
</telerik:RadEditor>
<br />
<asp:Button ID="btnSpremi" runat="server" Text="Spremi u bazu" OnClick="btnSpremi_Click" />
<br />
<br />
<asp:DataGrid ID="gridVijesti" runat="server" BorderWidth="1px" CellPadding="3"
AutoGenerateColumns="False" Width="620px"
OnItemCommand="gridVijesti_ItemCommand">
<HeaderStyle Font-Names="Verdana" ForeColor="Black" BackColor="#d3e5fa" />
<Columns>
<asp:BoundColumn DataField="vijestiID"></asp:BoundColumn>
<asp:ButtonColumn CommandName="Delete" ButtonType="LinkButton"
HeaderText="Obriši" Text="Delete"></asp:ButtonColumn>
<asp:ButtonColumn ButtonType="LinkButton" CommandName="Edit" HeaderText="Uredi" Text="Uredi"></asp:ButtonColumn>
<asp:BoundColumn DataField="Datum" HeaderText="Datum"></asp:BoundColumn>
<asp:BoundColumn DataField="TijeloVijesti" HeaderText="Tekst"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
</div>
problem is with the button btnSpremi no insert to database, tables are set to Datum-- datetame (data type) , vijestiID----int -is identity incremenet seed, and TijeloVijesti --nvarchar(MAX) .. .. unable to insert to database read from databse is working good delete also but insert nothing... please if you can look at the code,.. regards
//Populate the Area dropdown
protected void RadComboBoxArea_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
RadComboBox comboBox = (RadComboBox)sender;
// Clear the default Item that has been re-created from ViewState at this point.
comboBox.Items.Clear();
BindingList<LookupArea> Area = WellVentDataLayer.GetAreas(e.Text);
foreach (LookupArea i in Area)
{
comboBox.Items.Add(
new RadComboBoxItem(i._AreaName.ToString(), i._ID.ToString()));
}
comboBox.DataBind();
}
<%@ Page Language="C#" MasterPageFile="~/CMMasterPage.master" AutoEventWireup="true"
CodeFile="ActualvsRequired.aspx.cs" Inherits="Reports_ActualvsRequired" Title="Untitled Page" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Charting" TagPrefix="telerik" %>
<
asp:Content
ID
=
"Content2"
ContentPlaceHolderID
=
"header"
runat
=
"Server"
>
Resource Level
</
asp:Content
>
<
asp:Content
ID
=
"Content1"
ContentPlaceHolderID
=
"ContentPlaceHolder1"
runat
=
"Server"
>
<
link
href
=
"../Styles/CrewMetric_StyleSheet.css"
rel
=
"stylesheet"
type
=
"text/css"
/>
<
script
language
=
"javascript"
type
=
"text/javascript"
>
//Sys.Application.remove_load(RadWindowOpen);
//Sys.Application.add_load(RadWindowOpen);
var oWnd;
function RadWindowOpen() {
if (oWnd != null) {
oWnd.close();
}
oWnd = radopen("GridDisplay.aspx", null); ///Getting error
oWnd.setSize(200, 225);
oWnd.moveTo(1090, 160);
return false;
}
</
script
>
<
div
id
=
"divContentPage"
class
=
"subbody"
runat
=
"server"
>
<
div
style
=
"float: left; margin-left: 8px; margin-top: 10px;"
>
<
telerik:RadChart
runat
=
"Server"
ID
=
"RadChartAvR"
Width
=
"900px"
Height
=
"560"
OnItemDataBound
=
"RadChartAvR_ItemDataBound"
OnBeforeLayout
=
"RadChartAvR_BeforeLayout"
>
<
PlotArea
>
<
EmptySeriesMessage
Visible
=
"True"
>
<
Appearance
Visible
=
"True"
>
</
Appearance
>
</
EmptySeriesMessage
>
<
YAxis
>
<
AxisLabel
Visible
=
"true"
TextBlock-Text
=
"% of Actual Deviation from Requirement"
>
<
Appearance
Visible
=
"True"
>
</
Appearance
>
<
TextBlock
Text
=
"% of Actual Deviation from Requirement"
>
</
TextBlock
>
</
AxisLabel
>
</
YAxis
>
</
PlotArea
>
<
ChartTitle
Visible
=
"true"
>
</
ChartTitle
>
</
telerik:RadChart
>
</
div
>
<
div
style
=
"clear: both"
>
</
div
>
</
div
>
<
div
>
<
asp:HiddenField
ID
=
"hiddenCrewType"
runat
=
"server"
/>
</
div
>
<
telerik:RadWindowManager
ID
=
"RadWindowManager2"
runat
=
"server"
ReloadOnShow
=
"false"
Skin
=
"Sunset"
BackColor
=
"DodgerBlue"
EnableEmbeddedSkins
=
"false"
ShowContentDuringLoad
=
"False"
VisibleStatusbar
=
"False"
InitialBehavior
=
"None"
Behaviors
=
"Move"
Font-Names
=
"Tahoma"
VisibleOnPageLoad
=
"false"
Style
=
"z-index: 8000;"
EnableShadow
=
"true"
DestroyOnClose
=
"True"
>
</
telerik:RadWindowManager
>
</
asp:Content
>
ScriptManager
.RegisterStartupScript(this.Page, Page.GetType(), "test", "RadWindowOpen();", true);
private
void
CreateForecastGrid()
{
.
.
.
.
.
//Add the Notes column
GridTemplateColumn notes =
new
GridTemplateColumn();
RadGrid1.MasterTableView.Columns.Add(notes);
notes.ItemTemplate =
new
NotesDataGridTemplate(ListItemType.Item,
"lblNotes"
);
notes.EditItemTemplate =
new
NotesDataGridTemplate(ListItemType.EditItem,
"tbNotes"
);
notes.HeaderText =
"Notes"
;
notes.UniqueName =
"Notes"
;
notes.SortExpression =
"Notes"
;
//Add the Discipline column
.
.
.
//Add event handlers
RadGrid1.NeedDataSource +=
new
GridNeedDataSourceEventHandler(RadGrid1_OnNeedDataSource);
RadGrid1.ItemUpdated +=
new
GridUpdatedEventHandler(RadGrid1_ItemUpdated);
RadGrid1.ItemInserted +=
new
GridInsertedEventHandler(RadGrid1_ItemInserted);
RadGrid1.ItemDataBound +=
new
GridItemEventHandler(RadGrid1_OnItemDataBound);
RadGrid1.DataBound +=
new
EventHandler(RadGrid1_DataBound);
//Add the grid to the view
RadGridPlaceholder.Controls.Add(RadGrid1);
}
function setValues(d_diem_do) {
$find("<%= txtMA_DDO.ClientID %>").set_value(d_diem_do.MA_DDO);
$find("<%= dtpNGAY_HLUC.ClientID %>").set_selectedDate(d_diem_do.NGAY_HLUC);
$find("<%= chkCSPK.ClientID %>").checked = false; //Error here
}
$find("<%= chkCSPK.ClientID %>").checked = false;
is not run.var oWnd;
function pageLoad() {
if (oWnd != null) {
oWnd.close();
}
oWnd = radopen("GridDisplay.aspx", null);
oWnd.setSize(200, 225);
oWnd.moveTo(1090, 160);
return false;
}
<
telerik:RadScriptBlock
ID
=
"RadScriptBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
var obj = document.getElementById("<%#hiddenCrewType.ClientID%>")
alert(obj);
alert(1);
</
script
>
</
telerik:RadScriptBlock
>