Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
yvette
Yak Posting Veteran
74 Posts |
Posted - 2010-10-11 : 02:17:21
|
Hi,since i'm new to asp.net and sql server.may i know how to insert the data to sql server from gridview? |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-11 : 02:58:29
|
Read the gridview using a for each loop ..Inside the loop you can call a insert command to insert the values...Note: Loop length must be gridview.rows length |
|
|
yvette
Yak Posting Veteran
74 Posts |
Posted - 2010-10-11 : 03:01:41
|
quote: Originally posted by jafrywilson Read the gridview using a for each loop ..Inside the loop you can call a insert command to insert the values...Note: Loop length must be gridview.rows length
thanks for reply first...But is it any example??? |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-11 : 03:07:31
|
I think it will help you ...It's in vb.netprivate void button1_Click(object sender, EventArgs e){int i;string conStr = Properties.Settings.Default.connStr;SqlConnection con = new SqlConnection(conStr);con.Open();for (i = 0; i <= dataGridView1.Rows.Count - 1; i++){//Here in this for loop you can access all the values of//gridview and can store it in db by using ado.net likestring query = "insert into Table values(" + dataGridView1.Rows[i].Cells[0].Value + "," + dataGridView1.Rows[i].Cells[1].Value + ")";SqlCommand cmd = new SqlCommand(query, con);retval = cmd.ExecuteNonQuery();}con.Close();} |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-11 : 03:08:24
|
Refer this link for your reference..http://www.eggheadcafe.com/community/aspnet/14/10054280/how-to-insert-multiple-rows-from-gridview-in-databse.aspx |
|
|
yvette
Yak Posting Veteran
74 Posts |
Posted - 2010-10-11 : 03:19:50
|
Thanks for reply...my condition is the gridview is inside a tab control of devexpress.the other(not gridview) is work fine but the problem i don't know how to insert, edit, update, delete in gridview. |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-11 : 03:30:18
|
TO edit a row first you need to bind a row, datakey that can be a autogenerate id of your table ..Based on the id using a update command u can update the values that the user entered.. |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
|
yvette
Yak Posting Veteran
74 Posts |
Posted - 2010-10-11 : 03:41:32
|
i've try this, but problem occurs. cannot execute it.Anyone can help????This is the new customer page, i want to insert customer, car and job detail into sql server.the part insert the customer and car detail is work fine. both of this is stored using stored procedure.in job table, i have customer id, car plate no where both of this will auto pass the value to job table.Inside Job table have CustomerID, CarPlateNo, JobCode, JocDesc, JobStatus, JobRemarks, createddate and last modified date.Below is HTML code<%@ Page Title="" Language="C#" MasterPageFile="~/Master.master" AutoEventWireup="true" CodeFile="NewCustomer.aspx.cs" Inherits="NewCustomer" %><%@ Register assembly="DevExpress.Web.ASPxEditors.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dxe" %><%@ Register assembly="DevExpress.Web.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxRoundPanel" tagprefix="dxrp" %><%@ Register assembly="DevExpress.Web.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dxp" %><%@ Register assembly="DevExpress.Web.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxTabControl" tagprefix="dxtc" %><%@ Register assembly="DevExpress.Web.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxClasses" tagprefix="dxw" %><%@ Register assembly="DevExpress.Web.ASPxGridView.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxGridView" tagprefix="dxwgv" %><asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> <style type="text/css"> .style2 { width: 100%; } .style3 { width: 15%; } .style4 { width: 85%; } .style5 { width: 5%; } .style6 { width: 80%; } .style7 { width: 10%; } .style8 { width: 40%; } .style9 { width: 90%; } </style></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <form id="form1" runat="server"> <p> <br /> <dxe:ASPxLabel ID="lblNewCustomer" runat="server" Font-Size="Large" ForeColor="#0066FF" Text="New Customer"> </dxe:ASPxLabel> </p> <p> <dxe:ASPxButton ID="btnSave" runat="server" Text="Save"onclick="btnSave_Click"> </dxe:ASPxButton> </p> <p> <dxrp:ASPxRoundPanel ID="ASPxRoundPanel1" runat="server" Width="100%" HeaderText="Customer Information"> <PanelCollection><dxp:PanelContent runat="server"> <table class="style2"> <tr> <td class="style3"> Customer Name:</td> <td colspan="2" class="style4"> <dxe:ASPxTextBox ID="txtCustName" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> </tr> <tr> <td class="style3"> NRIC / Passport No:</td> <td colspan="2" class="style4"> <dxe:ASPxTextBox ID="txtIdentity" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> </tr> <tr> <td class="style3"> Tel:</td> <td class="style5"> Home</td> <td class="style6"> <dxe:ASPxTextBox ID="txtHomeTel" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> </tr> <tr> <td class="style3"> </td> <td class="style5"> H/P</td> <td class="style6"> <dxe:ASPxTextBox ID="txtMobileNo" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> </tr> </table> <br /> <hr style="color: #000000" /> <br /> <dxtc:ASPxPageControl ID="ASPxPageControl1" runat="server" ActiveTabIndex="2" width="100%"> <tabpages> <dxtc:TabPage Text="Address Information"> <contentcollection> <dxw:ContentControl runat="server"> <hr style="color: #000000" /> <table class="style2"> <tr> <td class="style7"> Address:</td> <td class="style9"> <dxe:ASPxTextBox ID="txtAddress" runat="server" Width="350px"> </dxe:ASPxTextBox> </td> </tr> <tr> <td class="style7"> Postal Code:</td> <td class="style9"> <dxe:ASPxTextBox ID="txtPostalCode" runat="server" Width="100px" MaxLength="5"> </dxe:ASPxTextBox> </td> </tr> <tr> <td class="style7"> City:</td> <td class="style9"> <dxe:ASPxTextBox ID="txtCity" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> </tr> <tr> <td class="style7"> State:</td> <td class="style9"> <asp:DropDownList ID="ddlState" runat="server" DataSourceID="SqlDataSource1" DataTextField="StateDesc" DataValueField="StateCode" Width="150px"> </asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:cwConnectionString %>" SelectCommand="SELECT [StateCode], [StateDesc] FROM [State]"> </asp:SqlDataSource> </td> </tr> </table> </dxw:ContentControl> </contentcollection> </dxtc:TabPage> <dxtc:TabPage Text="Car Details"> <contentcollection> <dxw:ContentControl runat="server"> <hr style="color: #000000" /> <br /> <table class="style2"> <tr> <td class="style7"> Car Plate No:</td> <td class="style8"> <dxe:ASPxTextBox ID="txtCarPlateNo" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> <td class="style7"> Car Model:</td> <td class="style8"> <asp:DropDownList ID="ddlCarModel" runat="server"> <asp:ListItem>toyota</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td class="style7"> Car Color:</td> <td class="style8"> <asp:DropDownList ID="ddlCarColor" runat="server"> <asp:ListItem>black</asp:ListItem> </asp:DropDownList> </td> <td class="style7"> Mileage:</td> <td class="style8"> <dxe:ASPxTextBox ID="txtMileage" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> </tr> <tr> <td class="style7"> Chasis No:</td> <td class="style8"> <dxe:ASPxTextBox ID="txtChasisNo" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> <td class="style7"> Engine No:</td> <td class="style8"> <dxe:ASPxTextBox ID="txtEngineNo" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> </tr> <tr> <td class="style7"> Date In:</td> <td class="style8"> <dxe:ASPxDateEdit ID="txtCarDateIn" runat="server"> </dxe:ASPxDateEdit> </td> <td class="style7"> Date Out:</td> <td class="style8"> <dxe:ASPxDateEdit ID="txtCarDateOut" runat="server"> </dxe:ASPxDateEdit> </td> </tr> <tr> <td class="style7"> Status:</td> <td> <asp:DropDownList ID="ddlCarStatus" runat="server"> <asp:ListItem>Waiting for service</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td class="style7"> Remarks:</td> <td> <dxe:ASPxTextBox ID="txtCarRemarks" runat="server" Width="300px"> </dxe:ASPxTextBox> </td> </tr> </table> </dxw:ContentControl> </contentcollection> </dxtc:TabPage> <dxtc:TabPage Text="Job Details"> <contentcollection> <dxw:ContentControl runat="server"> <hr style="color: #000000" /> <br /> <dxwgv:ASPxGridView ID="ASPxGridView1" runat="server" Width="100%" AutoGenerateColumns="False" DataSourceID="SqlDataSource2"> <Columns> <dxwgv:GridViewCommandColumn VisibleIndex="0"> <EditButton Visible="True"> </EditButton> <NewButton Visible="True"> </NewButton> </dxwgv:GridViewCommandColumn> <dxwgv:GridViewDataDropDownEditColumn FieldName="JobCode" VisibleIndex="1"> <DataItemTemplate> <asp:DropDownList ID="ddlJobCode" runat="server"> <asp:ListItem>J0002</asp:ListItem> <asp:ListItem>J0001</asp:ListItem> </asp:DropDownList> </DataItemTemplate> </dxwgv:GridViewDataDropDownEditColumn> <dxwgv:GridViewDataTextColumn FieldName="JobDesc" VisibleIndex="2"> <DataItemTemplate> <dxe:ASPxTextBox ID="txtJobDesc" runat="server" Height="22px" Width="309px"> </dxe:ASPxTextBox> </DataItemTemplate> </dxwgv:GridViewDataTextColumn> <dxwgv:GridViewDataDropDownEditColumn FieldName="Status" VisibleIndex="3"> <DataItemTemplate> <asp:DropDownList ID="ddlJobStatus" runat="server"> </asp:DropDownList> </DataItemTemplate> </dxwgv:GridViewDataDropDownEditColumn> <dxwgv:GridViewDataTextColumn FieldName="Remarks" VisibleIndex="4"> <DataItemTemplate> <dxe:ASPxTextBox ID="txtJobRemarks" runat="server" Height="22px" Width="309px"> </dxe:ASPxTextBox> </DataItemTemplate> </dxwgv:GridViewDataTextColumn> </Columns> </dxwgv:ASPxGridView> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:cwConnectionString %>" SelectCommand="SELECT [JobCode], [JobDesc], [Status], [Remarks] FROM [Job]"> </asp:SqlDataSource> </dxw:ContentControl> </contentcollection> </dxtc:TabPage> </tabpages> <TabStyle Width="15%"> </TabStyle> </dxtc:ASPxPageControl> </dxp:PanelContent></PanelCollection> </dxrp:ASPxRoundPanel> </p> </form></asp:Content>Below is my c# code behind.using System;using System.Data;using System.Configuration;using System.Data.SqlClient;using System.ComponentModel;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.Xml;public partial class NewCustomer : System.Web.UI.Page{ public SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString()); SqlDataAdapter ad = new SqlDataAdapter(); SqlCommand cmd = new SqlCommand(); DataTable dataTable; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { FillVendorGrid(); } } public string GetConnectionString() { return System.Configuration.ConfigurationManager.ConnectionStrings["cwConnectionString"].ConnectionString; } private void FillVendorGrid() { dataTable = new DataTable(); cmd.Connection = conn; cmd.CommandText = "SELECT [JobCode], [JobDesc], [Status], [Remarks] FROM Job"; ad = new SqlDataAdapter(cmd); ad.Fill(dataTable); ResultGridView.DataSource = dataTable; ResultGridView.DataBind(); } protected void ResultGridView_RowEditing(object sender, GridViewEditEventArgs e) { ResultGridView.EditIndex = e.NewEditIndex; FillVendorGrid(); } protected void ResultGridView_PageIndexChanging(object sender, GridViewPageEventArgs e) { ResultGridView.PageIndex = e.NewPageIndex; FillVendorGrid(); } protected void ResultGridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { cmd.Connection = conn; cmd.CommandText = "DELETE FROM Job WHERE JobCode='" + ResultGridView.DataKeys[e.RowIndex].Values[0].ToString() + "'"; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); FillVendorGrid(); } protected void ResultGridView_RowUpdating(object sender, GridViewUpdateEventArgs e) { DropDownList ddlJobCode = (DropDownList)ResultGridView.Rows[e.RowIndex].FindControl("ddlJobCode"); TextBox txtJobDesc = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtJobDesc"); DropDownList ddlJobStatus = (DropDownList)ResultGridView.Rows[e.RowIndex].FindControl("ddlJobStatus"); TextBox txtJobRemarks = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtJobRemarks"); cmd.Connection = conn; cmd.CommandText = "UPDATE Job SET JobCode ='" + ddlJobCode.SelectedItem.Value + "',JobDesc ='" + txtJobDesc.Text + "',JobStatus ='" + ddlJobStatus.SelectedItem.Value + "',JobRemarks ='" + txtJobRemarks.Text + "' WHERE JobCode='" + ResultGridView.DataKeys[e.RowIndex].Values[0].ToString() + "'"; conn.Open(); cmd.ExecuteNonQuery(); ResultGridView.EditIndex = -1; FillVendorGrid(); conn.Close(); } protected void ResultGridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { ResultGridView.EditIndex = -1; FillVendorGrid(); } protected void ResultGridView_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("AddNew")) { DropDownList ddlJobCode = (DropDownList)ResultGridView.Rows[e.RowIndex].FindControl("ddlJobCode"); TextBox txtJobDesc = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtJobDesc"); DropDownList ddlJobStatus = (DropDownList)ResultGridView.Rows[e.RowIndex].FindControl("ddlJobStatus"); TextBox txtJobRemarks = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtJobRemarks"); cmd.Connection = conn; cmd.CommandText = "INSERT INTO Job(JobCode, JobDesc,JobStatus,JobRemarks) Values('" + ddlJobCode.SelectedItem.Value + "', '" + txtJobDesc.Text + "', '" + ddlJobStatus.SelectedItem.Value + "', '" + txtJobRemarks.Text + "')"; conn.Open(); cmd.ExecuteNonQuery(); FillVendorGrid(); conn.Close(); } } protected void btnSave_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(GetConnectionString()); string sql = "sp_Insert_Into_Customer_Car"; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.CommandType = CommandType.StoredProcedure; string CustomerName = txtCustName.Text; string Identity = txtIdentity.Text; string HomeTel = txtHomeTel.Text; string MobileNo = txtMobileNo.Text; string Address = txtAddress.Text; string PostalCode = txtPostalCode.Text; string City = txtCity.Text; string State = ddlState.SelectedItem.Value; string CarPlateNo = txtCarPlateNo.Text; string CarModel = ddlCarModel.SelectedItem.Value; string CarColor = ddlCarColor.SelectedItem.Value; string Mileage = txtMileage.Text; string ChasisNo = txtChasisNo.Text; string EngineNo = txtEngineNo.Text; string DateIn = txtCarDateIn.Text; string DateOut = txtCarDateOut.Text; string Status = ddlCarStatus.SelectedItem.Value; string Remarks = txtCarRemarks.Text; cmd.Parameters.AddWithValue("@CarOwnerName", txtCustName.Text); cmd.Parameters.AddWithValue("@Identity", txtIdentity.Text); cmd.Parameters.AddWithValue("@HomeTel", txtHomeTel.Text); cmd.Parameters.AddWithValue("@MobileNo", txtMobileNo.Text); cmd.Parameters.AddWithValue("@Address", txtAddress.Text); cmd.Parameters.AddWithValue("@PostalCode", txtPostalCode.Text); cmd.Parameters.AddWithValue("@City", txtCity.Text); cmd.Parameters.AddWithValue("@State", ddlState.SelectedItem.Value); cmd.Parameters.AddWithValue("@CarPlateNo", txtCarPlateNo.Text); cmd.Parameters.AddWithValue("@CarModel", ddlCarModel.SelectedItem.Value); cmd.Parameters.AddWithValue("@CarColor", ddlCarColor.SelectedItem.Value); cmd.Parameters.AddWithValue("@Mileage", txtMileage.Text); cmd.Parameters.AddWithValue("@ChasisNo", txtChasisNo.Text); cmd.Parameters.AddWithValue("@EngineNo", txtEngineNo.Text); cmd.Parameters.AddWithValue("@DateIn", txtCarDateIn.Text); cmd.Parameters.AddWithValue("@DateOut", txtCarDateOut.Text); cmd.Parameters.AddWithValue("@Status", ddlCarStatus.SelectedItem.Value); cmd.Parameters.AddWithValue("@Remarks", txtCarRemarks.Text); cmd.ExecuteNonQuery(); //int s = cmd.ExecuteNonQuery(); //if (s == 1) //{ // Response.Redirect("Login.aspx"); //} //else //{ // Response.Redirect("Register.aspx"); //} } catch (System.Data.SqlClient.SqlException ex_msg) { //Here will be catch elements string msg = "Error occured while inserting"; msg += ex_msg.Message; throw new Exception(msg); } finally { //Here will be fially elements conn.Close(); } }} |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-11 : 03:45:49
|
Post your Report.. |
|
|
yvette
Yak Posting Veteran
74 Posts |
Posted - 2010-10-11 : 03:50:43
|
quote: Originally posted by jafrywilson Post your Report..
Sorry to ask.What report??? |
|
|
yvette
Yak Posting Veteran
74 Posts |
Posted - 2010-10-11 : 03:52:43
|
HTML Code<%@ Page Title="" Language="C#" MasterPageFile="~/Master.master" AutoEventWireup="true" CodeFile="NewCustomer.aspx.cs" Inherits="NewCustomer" %><%@ Register assembly="DevExpress.Web.ASPxEditors.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dxe" %><%@ Register assembly="DevExpress.Web.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxRoundPanel" tagprefix="dxrp" %><%@ Register assembly="DevExpress.Web.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dxp" %><%@ Register assembly="DevExpress.Web.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxTabControl" tagprefix="dxtc" %><%@ Register assembly="DevExpress.Web.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxClasses" tagprefix="dxw" %><%@ Register assembly="DevExpress.Web.ASPxGridView.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxGridView" tagprefix="dxwgv" %><asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> <style type="text/css"> .style2 { width: 100%; } .style3 { width: 15%; } .style4 { width: 85%; } .style5 { width: 5%; } .style6 { width: 80%; } .style7 { width: 10%; } .style8 { width: 40%; } .style9 { width: 90%; } </style></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <form id="form1" runat="server"> <p> <br /> <dxe:ASPxLabel ID="lblNewCustomer" runat="server" Font-Size="Large" ForeColor="#0066FF" Text="New Customer"> </dxe:ASPxLabel> </p> <p> <dxe:ASPxButton ID="btnSave" runat="server" Text="Save"onclick="btnSave_Click"> </dxe:ASPxButton> </p> <p> <dxrp:ASPxRoundPanel ID="ASPxRoundPanel1" runat="server" Width="100%" HeaderText="Customer Information"> <PanelCollection><dxp:PanelContent runat="server"> <table class="style2"> <tr> <td class="style3"> Customer Name:</td> <td colspan="2" class="style4"> <dxe:ASPxTextBox ID="txtCustName" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> </tr> <tr> <td class="style3"> NRIC / Passport No:</td> <td colspan="2" class="style4"> <dxe:ASPxTextBox ID="txtIdentity" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> </tr> <tr> <td class="style3"> Tel:</td> <td class="style5"> Home</td> <td class="style6"> <dxe:ASPxTextBox ID="txtHomeTel" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> </tr> <tr> <td class="style3"> </td> <td class="style5"> H/P</td> <td class="style6"> <dxe:ASPxTextBox ID="txtMobileNo" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> </tr> </table> <br /> <hr style="color: #000000" /> <br /> <dxtc:ASPxPageControl ID="ASPxPageControl1" runat="server" ActiveTabIndex="2" width="100%"> <tabpages> <dxtc:TabPage Text="Address Information"> <contentcollection> <dxw:ContentControl runat="server"> <hr style="color: #000000" /> <table class="style2"> <tr> <td class="style7"> Address:</td> <td class="style9"> <dxe:ASPxTextBox ID="txtAddress" runat="server" Width="350px"> </dxe:ASPxTextBox> </td> </tr> <tr> <td class="style7"> Postal Code:</td> <td class="style9"> <dxe:ASPxTextBox ID="txtPostalCode" runat="server" Width="100px" MaxLength="5"> </dxe:ASPxTextBox> </td> </tr> <tr> <td class="style7"> City:</td> <td class="style9"> <dxe:ASPxTextBox ID="txtCity" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> </tr> <tr> <td class="style7"> State:</td> <td class="style9"> <asp:DropDownList ID="ddlState" runat="server" DataSourceID="SqlDataSource1" DataTextField="StateDesc" DataValueField="StateCode" Width="150px"> </asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:cwConnectionString %>" SelectCommand="SELECT [StateCode], [StateDesc] FROM [State]"> </asp:SqlDataSource> </td> </tr> </table> </dxw:ContentControl> </contentcollection> </dxtc:TabPage> <dxtc:TabPage Text="Car Details"> <contentcollection> <dxw:ContentControl runat="server"> <hr style="color: #000000" /> <br /> <table class="style2"> <tr> <td class="style7"> Car Plate No:</td> <td class="style8"> <dxe:ASPxTextBox ID="txtCarPlateNo" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> <td class="style7"> Car Model:</td> <td class="style8"> <asp:DropDownList ID="ddlCarModel" runat="server"> <asp:ListItem>toyota</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td class="style7"> Car Color:</td> <td class="style8"> <asp:DropDownList ID="ddlCarColor" runat="server"> <asp:ListItem>black</asp:ListItem> </asp:DropDownList> </td> <td class="style7"> Mileage:</td> <td class="style8"> <dxe:ASPxTextBox ID="txtMileage" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> </tr> <tr> <td class="style7"> Chasis No:</td> <td class="style8"> <dxe:ASPxTextBox ID="txtChasisNo" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> <td class="style7"> Engine No:</td> <td class="style8"> <dxe:ASPxTextBox ID="txtEngineNo" runat="server" Width="170px"> </dxe:ASPxTextBox> </td> </tr> <tr> <td class="style7"> Date In:</td> <td class="style8"> <dxe:ASPxDateEdit ID="txtCarDateIn" runat="server"> </dxe:ASPxDateEdit> </td> <td class="style7"> Date Out:</td> <td class="style8"> <dxe:ASPxDateEdit ID="txtCarDateOut" runat="server"> </dxe:ASPxDateEdit> </td> </tr> <tr> <td class="style7"> Status:</td> <td> <asp:DropDownList ID="ddlCarStatus" runat="server"> <asp:ListItem>Waiting for service</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td class="style7"> Remarks:</td> <td> <dxe:ASPxTextBox ID="txtCarRemarks" runat="server" Width="300px"> </dxe:ASPxTextBox> </td> </tr> </table> </dxw:ContentControl> </contentcollection> </dxtc:TabPage> <dxtc:TabPage Text="Job Details"> <contentcollection> <dxw:ContentControl runat="server"> <hr style="color: #000000" /> <br /> <dxwgv:ASPxGridView ID="GVJob" runat="server" Width="100%" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" DataKeyNames="JobCode OnPageIndexChanging="GVJob_PageIndexChanging" OnRowDeleting="GVJob_RowDeleting" OnRowEditing="GVJob_RowEditing" OnRowUpdating="GVJob_RowUpdating" OnRowCancelingEdit="GVJob_RowCancelingEdit" OnRowCommand="ResultGridView_RowCommand"> <Columns> <dxwgv:GridViewCommandColumn VisibleIndex="0"> <EditButton Visible="True"> </EditButton> <NewButton Visible="True"> </NewButton> </dxwgv:GridViewCommandColumn> <dxwgv:GridViewDataDropDownEditColumn FieldName="JobCode" VisibleIndex="1"> <DataItemTemplate> <asp:DropDownList ID="ddlJobCode" runat="server"> <asp:ListItem>J0002</asp:ListItem> <asp:ListItem>J0001</asp:ListItem> </asp:DropDownList> </DataItemTemplate> </dxwgv:GridViewDataDropDownEditColumn> <dxwgv:GridViewDataTextColumn FieldName="JobDesc" VisibleIndex="2"> <DataItemTemplate> <dxe:ASPxTextBox ID="txtJobDesc" runat="server" Height="22px" Width="309px"> </dxe:ASPxTextBox> </DataItemTemplate> </dxwgv:GridViewDataTextColumn> <dxwgv:GridViewDataDropDownEditColumn FieldName="Status" VisibleIndex="3"> <DataItemTemplate> <asp:DropDownList ID="ddlJobStatus" runat="server"> </asp:DropDownList> </DataItemTemplate> </dxwgv:GridViewDataDropDownEditColumn> <dxwgv:GridViewDataTextColumn FieldName="Remarks" VisibleIndex="4"> <DataItemTemplate> <dxe:ASPxTextBox ID="txtJobRemarks" runat="server" Height="22px" Width="309px"> </dxe:ASPxTextBox> </DataItemTemplate> </dxwgv:GridViewDataTextColumn> </Columns> </dxwgv:ASPxGridView> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:cwConnectionString %>" SelectCommand="SELECT [JobCode], [JobDesc], [Status], [Remarks] FROM [Job]"> </asp:SqlDataSource> </dxw:ContentControl> </contentcollection> </dxtc:TabPage> </tabpages> <TabStyle Width="15%"> </TabStyle> </dxtc:ASPxPageControl> </dxp:PanelContent></PanelCollection> </dxrp:ASPxRoundPanel> </p> </form></asp:Content>C# Code behindusing System;using System.Data;using System.Configuration;using System.Data.SqlClient;using System.ComponentModel;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.Xml;public partial class NewCustomer : System.Web.UI.Page{ public SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString()); SqlDataAdapter ad = new SqlDataAdapter(); SqlCommand cmd = new SqlCommand(); DataTable dataTable; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { FillVendorGrid(); } } public string GetConnectionString() { return System.Configuration.ConfigurationManager.ConnectionStrings["cwConnectionString"].ConnectionString; } private void FillVendorGrid() { dataTable = new DataTable(); cmd.Connection = conn; cmd.CommandText = "SELECT [JobCode], [JobDesc], [Status], [Remarks] FROM Job"; ad = new SqlDataAdapter(cmd); ad.Fill(dataTable); GVJob.DataSource = dataTable; GVJob.DataBind(); } protected void GVJob_RowEditing(object sender, GridViewEditEventArgs e) { GVJob.EditIndex = e.NewEditIndex; FillVendorGrid(); } protected void GVJob_PageIndexChanging(object sender, GridViewPageEventArgs e) { GVJob.PageIndex = e.NewPageIndex; FillVendorGrid(); } protected void GVJob_RowDeleting(object sender, GridViewDeleteEventArgs e) { cmd.Connection = conn; cmd.CommandText = "DELETE FROM Job WHERE JobCode='" + GVJob.DataKeys[e.RowIndex].Values[0].ToString() + "'"; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); FillVendorGrid(); } protected void GVJob_RowUpdating(object sender, GridViewUpdateEventArgs e) { DropDownList ddlJobCode = (DropDownList)GVJob.Rows[e.RowIndex].FindControl("ddlJobCode"); TextBox txtJobDesc = (TextBox)GVJob.Rows[e.RowIndex].FindControl("txtJobDesc"); DropDownList ddlJobStatus = (DropDownList)GVJob.Rows[e.RowIndex].FindControl("ddlJobStatus"); TextBox txtJobRemarks = (TextBox)GVJob.Rows[e.RowIndex].FindControl("txtJobRemarks"); cmd.Connection = conn; cmd.CommandText = "UPDATE Job SET JobCode ='" + ddlJobCode.SelectedItem.Value + "',JobDesc ='" + txtJobDesc.Text + "',JobStatus ='" + ddlJobStatus.SelectedItem.Value + "',JobRemarks ='" + txtJobRemarks.Text + "' WHERE JobCode='" + ResultGridView.DataKeys[e.RowIndex].Values[0].ToString() + "'"; conn.Open(); cmd.ExecuteNonQuery(); GVJob.EditIndex = -1; FillVendorGrid(); conn.Close(); } protected void GVJob_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GVJob.EditIndex = -1; FillVendorGrid(); } protected void GVJob_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("AddNew")) { DropDownList ddlJobCode = (DropDownList)GVJob.Rows[e.RowIndex].FindControl("ddlJobCode"); TextBox txtJobDesc = (TextBox)GVJob.Rows[e.RowIndex].FindControl("txtJobDesc"); DropDownList ddlJobStatus = (DropDownList)GVJob.Rows[e.RowIndex].FindControl("ddlJobStatus"); TextBox txtJobRemarks = (TextBox)GVJob.Rows[e.RowIndex].FindControl("txtJobRemarks"); cmd.Connection = conn; cmd.CommandText = "INSERT INTO Job(JobCode, JobDesc,JobStatus,JobRemarks) Values('" + ddlJobCode.SelectedItem.Value + "', '" + txtJobDesc.Text + "', '" + ddlJobStatus.SelectedItem.Value + "', '" + txtJobRemarks.Text + "')"; conn.Open(); cmd.ExecuteNonQuery(); FillVendorGrid(); conn.Close(); } } protected void btnSave_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(GetConnectionString()); string sql = "sp_Insert_Into_Customer_Car"; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.CommandType = CommandType.StoredProcedure; string CustomerName = txtCustName.Text; string Identity = txtIdentity.Text; string HomeTel = txtHomeTel.Text; string MobileNo = txtMobileNo.Text; string Address = txtAddress.Text; string PostalCode = txtPostalCode.Text; string City = txtCity.Text; string State = ddlState.SelectedItem.Value; string CarPlateNo = txtCarPlateNo.Text; string CarModel = ddlCarModel.SelectedItem.Value; string CarColor = ddlCarColor.SelectedItem.Value; string Mileage = txtMileage.Text; string ChasisNo = txtChasisNo.Text; string EngineNo = txtEngineNo.Text; string DateIn = txtCarDateIn.Text; string DateOut = txtCarDateOut.Text; string Status = ddlCarStatus.SelectedItem.Value; string Remarks = txtCarRemarks.Text; cmd.Parameters.AddWithValue("@CarOwnerName", txtCustName.Text); cmd.Parameters.AddWithValue("@Identity", txtIdentity.Text); cmd.Parameters.AddWithValue("@HomeTel", txtHomeTel.Text); cmd.Parameters.AddWithValue("@MobileNo", txtMobileNo.Text); cmd.Parameters.AddWithValue("@Address", txtAddress.Text); cmd.Parameters.AddWithValue("@PostalCode", txtPostalCode.Text); cmd.Parameters.AddWithValue("@City", txtCity.Text); cmd.Parameters.AddWithValue("@State", ddlState.SelectedItem.Value); cmd.Parameters.AddWithValue("@CarPlateNo", txtCarPlateNo.Text); cmd.Parameters.AddWithValue("@CarModel", ddlCarModel.SelectedItem.Value); cmd.Parameters.AddWithValue("@CarColor", ddlCarColor.SelectedItem.Value); cmd.Parameters.AddWithValue("@Mileage", txtMileage.Text); cmd.Parameters.AddWithValue("@ChasisNo", txtChasisNo.Text); cmd.Parameters.AddWithValue("@EngineNo", txtEngineNo.Text); cmd.Parameters.AddWithValue("@DateIn", txtCarDateIn.Text); cmd.Parameters.AddWithValue("@DateOut", txtCarDateOut.Text); cmd.Parameters.AddWithValue("@Status", ddlCarStatus.SelectedItem.Value); cmd.Parameters.AddWithValue("@Remarks", txtCarRemarks.Text); cmd.ExecuteNonQuery(); //int s = cmd.ExecuteNonQuery(); //if (s == 1) //{ // Response.Redirect("Login.aspx"); //} //else //{ // Response.Redirect("Register.aspx"); //} } catch (System.Data.SqlClient.SqlException ex_msg) { //Here will be catch elements string msg = "Error occured while inserting"; msg += ex_msg.Message; throw new Exception(msg); } finally { //Here will be fially elements conn.Close(); } }}the red color part is the gridview part. other part is work fine. |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-11 : 03:53:16
|
Sorry Error report you got.. |
|
|
yvette
Yak Posting Veteran
74 Posts |
Posted - 2010-10-11 : 03:54:14
|
this have cause 20 errors... |
|
|
yvette
Yak Posting Veteran
74 Posts |
Posted - 2010-10-11 : 03:59:44
|
(1)'DevExpress.Web.ASPxGridView.ASPxGridView' does not contain a definition for 'EditIndex' and no extension method 'EditIndex' accepting a first argument of type 'DevExpress.Web.ASPxGridView.ASPxGridView' could be found (are you missing a using directive or an assembly reference?)(2)'DevExpress.Web.ASPxGridView.ASPxGridView' does not contain a definition for 'DataKeys' and no extension method 'DataKeys' accepting a first argument of type 'DevExpress.Web.ASPxGridView.ASPxGridView' could be found (are you missing a using directive or an assembly reference?)(3)'DevExpress.Web.ASPxGridView.ASPxGridView' does not contain a definition for 'Rows' and no extension method 'Rows' accepting a first argument of type 'DevExpress.Web.ASPxGridView.ASPxGridView' could be found (are you missing a using directive or an assembly reference?)(4)'System.Web.UI.WebControls.GridViewCommandEventArgs' does not contain a definition for 'RowIndex' and no extension method 'RowIndex' accepting a first argument of type 'System.Web.UI.WebControls.GridViewCommandEventArgs' could be found (are you missing a using directive or an assembly reference?)(5)No overload for 'GVJob_RowDeleting' matches delegate 'DevExpress.Web.Data.ASPxDataDeletingEventHandler'(6)No overload for 'GVJob_RowUpdating' matches delegate 'DevExpress.Web.Data.ASPxDataUpdatingEventHandler'(7)No overload for 'GVJob_RowCommand' matches delegate 'DevExpress.Web.ASPxGridView.ASPxGridViewRowCommandEventHandler'this is the error. another 13 error have duplicate from above error. |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-11 : 04:01:45
|
Ok post it..It will help for easy correction.. |
|
|
yvette
Yak Posting Veteran
74 Posts |
Posted - 2010-10-11 : 04:07:00
|
Thanks in advance... |
|
|
yvette
Yak Posting Veteran
74 Posts |
Posted - 2010-10-11 : 04:13:48
|
and this is the webconfig file.<appSettings> <add key="cwConnectionString" value="Data Source=YVETTE-PC\SQLEXPRESS08;Initial Catalog=cw;User ID=sa;Password=p@ssword;"/> </appSettings>above is my code add at config file. |
|
|
|
|
|
|
|