Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 10th, 2005, 11:46 PM
Authorized User
 
Join Date: Aug 2004
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Baby_programmer Send a message via MSN to Baby_programmer Send a message via Yahoo to Baby_programmer
Default

Imar obviously i'll go for paging in datagrid ... but the requirement is to update the grid cell with no post backs it must be same as in windows application...The grid must not post back when i update the cell ...i want t o send u screenshot of what i want ... tell me some address if u need to see.... Thanx

ashfaq
 
Old April 11th, 2005, 01:10 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

No need for a screen shot as I think I understand what you want. And still, the answer is client side call backs.
Quote:
quote:Originally posted by Imar
Did you experiment with client side call backs? Did you try any of the examples?
And? Did you?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old April 11th, 2005, 04:15 AM
Authorized User
 
Join Date: Aug 2004
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Baby_programmer Send a message via MSN to Baby_programmer Send a message via Yahoo to Baby_programmer
Default

Imar client call back in asp.net1.x is not present , as u know its in whidbey.... well i have an example iam qouting it...


.................................................. ..............
public class WebForm1 : System.Web.UI.Page

    {
        protected System.Web.UI.WebControls.DataGrid dgCustomers;

        private string str ="server=ws13;uid=sa;pwd=;database=Northwind";
        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            string connStr = str;
            string sql = "SELECT CustomerID,CompanyName,ContactName FROM Customers";
            SqlConnection dataConn = new SqlConnection(connStr);
            SqlDataAdapter adap = new SqlDataAdapter(sql,dataConn);
            DataSet ds = new DataSet();
            adap.Fill(ds,"Customers");
            dgCustomers.DataSource = ds.Tables["Customers"].DefaultView;
            dgCustomers.DataBind();
        }


.................................................. ..............

<table width="712" cellpadding="0" class="borders" height="245">
                        <tr bgcolor="#cccccc">
                            <td width="192"><b>Customer Name:</b></td>
                            <td width="176"><b>Company Name:</b></td>
                            <td width="219"><b>Customer ID:</b></td>
                        </tr>
                        <tr>
                            <td colspan="3" width="535" vAlign="top" align="center">
                                <div style="OVERFLOW:auto">
                                    <asp:DataGrid ShowHeader="False" ID="dgCustomers" BorderWidth="0px" Cellpadding="0" Width="696px"
                                        Runat="server" AutoGenerateColumns="False">
                                        <AlternatingItemStyle Font-Names="arial" BackColor="#EFEFEF"></AlternatingItemStyle>
                                        <ItemStyle Font-Names="arial" VerticalAlign="Top"></ItemStyle>
                                        <Columns>
                                            <asp:BoundColumn DataField="ContactName">
                                                <ItemStyle VerticalAlign="Top"></ItemStyle>
                                            </asp:BoundColumn>
                                            <asp:BoundColumn DataField="CompanyName">
                                                <ItemStyle VerticalAlign="Top"></ItemStyle>
                                            </asp:BoundColumn>
                                            <asp:TemplateColumn>
                                                <ItemTemplate>
                                                    <SPAN title="Edit Customer" style="CURSOR: hand; COLOR: #02027a; TEXT-DECORATION: underline"
                                                    onClick="GetCustomerData('<%# DataBinder.Eval(Container.DataItem,"CustomerID")%> ')">
                                                        <%# DataBinder.Eval(Container.DataItem,"CustomerID")%> </SPAN>
                                                </ItemTemplate>
                                            </asp:TemplateColumn>
                                        </Columns>
                                    </asp:DataGrid>
                                </div>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <span id="spanInsert" style="FONT-WEIGHT:bold;CURSOR:hand;COLOR:#02027a" onClick="ClearCustomerData()">Insert New Customer</span>
                    <p>
                        <span id="spanMessage" class="text"></span>
                        <table id="tblCustomerData" class="borders" style="DISPLAY:none" cellpadding="4">
                            <tr bgcolor="#efefef">
                                <td colspan="5">
                                    <b>Customer Details:</b>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <b>Customer ID:</b>
                                </td>
                                <td>&nbsp;&nbsp; <INPUT id="dcCustomerID" type="text" size="16">
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                                <td>
                                    <b>Company Name:</b>
                                </td>
                                <td>
                                    <input type="text" id="dcCompanyName" size="30">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <b>Customer Name:</b>
                                </td>
                                <td>
                                    <input type="text" id="dcContactName" size="30">
                                </td>
                                <td>&nbsp;</td>
                                <td>
                                    <b>Contact Title:</b>
                                </td>
                                <td>
                                    <input type="text" id="dcContactTitle" size="30">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <b>Contact Address:</b>
                                </td>
                                <td>
                                    <input type="text" id="dcAddress" size="30">
                                </td>
                                <td>&nbsp;</td>
                                <td>
                                    <b>Contact City:</b>
                                </td>
                                <td>
                                    <input type="text" id="dcCity" size="30">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <b>Contact Region:</b>
                                </td>
                                <td>
                                    <input type="text" id="dcRegion" size="30">
                                </td>
                                <td>&nbsp;</td>
                                <td>
                                    <b>Contact PostalCode:</b>
                                </td>
                                <td>
                                    <input type="text" id="dcPostalCode" size="30">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <b>Contact Country:</b>
                                </td>
                                <td>
                                    <input type="text" id="dcCountry" size="30">
                                </td>
                                <td>&nbsp;</td>
                                <td>
                                    <b>Contact Phone:</b>
                                </td>
                                <td>
                                    <input type="text" id="dcPhone" size="30">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <b>Contact Fax:</b>
                                </td>
                                <td>
                                    <input type="text" id="dcFax" size="30">
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">&nbsp;&nbsp;<INPUT id="btnSubmitUpdate" onclick="GenerateCustomerData('update')" type="submit" value="Update">
                                    &nbsp; <input type="submit" id="btnSubmitDelete" value="Delete" onclick="GenerateCustomerData('delete')">
                                    &nbsp;&nbsp; <input type="submit" id="btnSubmitInsert" value="Insert" onclick="GenerateCustomerData('insert')">
                                    &nbsp;&nbsp; <input type="submit" id="btnSubmitCancel" value="Cancel" onclick="tblCustomerData.style.display = 'none'">
                                </td>
                            </tr>
                        </table>
                    </p>
                </td>
            </tr>
            </TD></TR>
        </table>

.................................................. ...............

    [WebMethod]
        public DataSet GetCustomerData(string customerID)
        {
            string sql = "SELECT * FROM Customers WHERE CustomerID='" + customerID + "'";
            SqlConnection dataConn = new SqlConnection(connStr);
            SqlDataAdapter adap = new SqlDataAdapter(sql,dataConn);
            DataSet ds = new DataSet();
            adap.Fill(ds,"CustomersWS");
            return ds;
        }

        [WebMethod]
        public bool UpdateCustomerData(XmlNode xmlData)
        {
            ArrayList cols = new ArrayList();
            ArrayList vals = new ArrayList();
            StringBuilder sql = new StringBuilder();
            bool foundRoot = false;
            bool inKey = false;
            string keyName,keyValue,keyType,commandType,table;
            keyName = keyValue = keyType = commandType = table = String.Empty;

            //Create connection object and start reading XML
            SqlConnection dataConn = new SqlConnection(connStr);
            XmlNodeReader reader = null;
            try
            {
                reader = new XmlNodeReader(xmlData);
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            //Only hit this section if the root element has already
                            //been processed. This is tracked by foundRoot bool
                            if (foundRoot)
                            {
                                //Look for key attribute
                                if (Convert.ToBoolean(reader.GetAttribute("key")))
                                {
                                    inKey = true;
                                    keyType = reader.GetAttribute("keyType");
                                }
                                string name = reader.Name;
                                string text = reader.ReadString();

                                if (commandType == "insert")
                                {
                                    cols.Add(name);
                                    vals.Add("'" + text + "'");
                                }
                                else if (commandType == "update")
                                {
                                    //Combine column and value into cols
                                    //ArrayList for Update
                                    cols.Add(name + "='" + text + "'");
                                }
                                if (inKey)
                                {
                                    keyName = name;
                                    keyValue = text;
                                    if (commandType == "delete") reader.Close();
                                    inKey = false;
                                }
                            }
                            else
                            {
                                table = reader.Name;
                                foundRoot = true;
                                commandType = reader.GetAttribute("commandType");
                            }
                            break;
                    }
                }
                if (reader != null) reader.Close();

                //Create string[] arrays so that we can use the String class's Join() method
                string[] colsArray = new String[cols.Count];
                cols.CopyTo(colsArray);

                string[] valsArray = new String[vals.Count];
                vals.CopyTo(valsArray);

                //Generate SQL statement
                if (commandType == "insert")
                {
                    sql.Append("INSERT INTO ");
                    sql.Append(table);
                    sql.Append(" (");
                    sql.Append(string.Join(",",colsArray));
                    sql.Append(") VALUES (");
                    sql.Append(string.Join(",",valsArray));
                    sql.Append(") ");
                }
                else if (commandType == "update")
                {
                    sql.Append("UPDATE ");
                    sql.Append(table);
                    sql.Append(" SET ");
                    sql.Append(string.Join(",",colsArray));
                    sql.Append(" WHERE ");
                    sql.Append(keyName);
                    sql.Append("=");
                    if (keyType == "string") sql.Append("'");
                    sql.Append(keyValue);
                    if (keyType == "string") sql.Append("'");
                }
                else if (commandType == "delete")
                {
                    sql.Append("DELETE FROM ");
                    sql.Append(table);
                    sql.Append(" WHERE ");
                    sql.Append(keyName);
                    sql.Append("=");
                    if (keyType == "string") sql.Append("'");
                    sql.Append(keyValue);
                    if (keyType == "string") sql.Append("'");
                }

                SqlCommand cmd = new SqlCommand(sql.ToString(),dataConn);
                dataConn.Open();
                cmd.ExecuteNonQuery();
                return true;
            }
            catch (Exception exp)
            {
                return false;
            }
            finally
            {
                if (reader != null) reader.Close();
                dataConn.Close();
            }
        }


.................................................. ....................
save code below in customers.js file


var wsCallID;
var key = "CustomerID";
var instanceCommandType = "";

function Init() {
    var webServicePath = "WebServices/Customers.asmx?WSDL";
    webService.useService(webServicePath,"wsSend");
}

function GetCustomerData(customerID) {
    ChangeCursor("wait");
    wsCallID = webService.wsSend.callService(onWSGetCustomerData,
               "GetCustomerData", customerID);
}

function onWSGetCustomerData(result) {
    if (result.error) {
        // Pull the error information from the result.errorDetail properties
        var xfaultcode = result.errorDetail.code;
        var xfaultstring = result.errorDetail.string;
        var xfaultsoap = result.errorDetail.raw;
        alert("Error returned from Web Service: " + xfaultcode + " " + xfaultstring);
    } else if(!result.error) {
        var returnData = new ActiveXObject("MSXML2.DOMDocument");
        returnData.async = false;
        returnData.documentElement = result.value;
        BindCustomerData(returnData);
        returnData = null;
    }
    ChangeCursor("default");
}

function BindCustomerData(xmlData) {
    document.all.spanMessage.innerText = "";
    document.all.tblCustomerData.style.display = "block";
    document.all.btnSubmitInsert.disabled = true;
    document.all.btnSubmitUpdate.disabled = false;
    document.all.btnSubmitDelete.disabled = false;
    var customers = xmlData.selectSingleNode("//CustomersWS");
    if (customers != null) {
        for (var i=0;i<customers.childNodes.length;i++) {
            var childNode = customers.childNodes(i);
            if (document.all("dc" + childNode.nodeName)) {
                document.all("dc" + childNode.nodeName).value = childNode.text;
            }
        }
    }

}

function GenerateCustomerData(commandType) {
    instanceCommandType = commandType;
    var inputs = document.all.tags("INPUT");
    var xmlDoc = new ActiveXObject("MSXML2.DOMDocument");
    var customersNode = xmlDoc.createElement("Customers");
    customersNode.setAttribute("commandType",commandTy pe);
    xmlDoc.appendChild(customersNode);
    var name,val,textbox,elemNode,textNode;
    for (var i=0;i<inputs.length;i++) {
        textBox = inputs.item(i);
        if (textBox.id != null && textBox.id != "" && textBox.id.indexOf("dc") == 0) {
            name = textBox.id.substring(2,textBox.id.length);
            val = textBox.value;
            elemNode = xmlDoc.createElement(name);
            //Identify the key
            if (name == key) {
                elemNode.setAttribute("key","true");
                elemNode.setAttribute("keyType","string");
            }

            textNode = xmlDoc.createTextNode(val);
            elemNode.appendChild(textNode);
            customersNode.appendChild(elemNode);
        }
    }
    if (commandType == "delete") {
        var lastChance = confirm("Are you sure you want to delete this record?");
        if (!lastChance) return false;
    }
    //Take this out for your application
    //if (commandType != "delete") {
        UpdateCustomerData(xmlDoc);
    //}
    //else {
    // alert("Delete functionality has been disabled.");
    //}

}

function ClearCustomerData() {
    //Clear out textboxes
    var inputs = document.all.tags("INPUT");
    for (var i=0;i<inputs.length;i++) {
        textBox = inputs.item(i);
        if (textBox.id.indexOf("dc") == 0) {
            textBox.value = "";
        }
    }
    document.all.spanMessage.style.display = "none";
    document.all.tblCustomerData.style.display = "block";
    document.all.btnSubmitInsert.disabled = false;
    document.all.btnSubmitUpdate.disabled = true;
    document.all.btnSubmitDelete.disabled = true;
}

function UpdateCustomerData(xmlDocument) {
    ChangeCursor("wait");
    wsCallID = webService.wsSend.callService(onWSUpdateCustomerDa ta,
               "UpdateCustomerData", xmlDocument);
}

function onWSUpdateCustomerData(result) {
    var status = false;
    if (result.error) {
        // Pull the error information from the result.errorDetail properties
        var xfaultcode = result.errorDetail.code;
        var xfaultstring = result.errorDetail.string;
        var xfaultsoap = result.errorDetail.raw;
        alert("Error returned from Web Service: " + xfaultcode + " " + xfaultstring);
    } else if(!result.error) {
        status = result.value;
    }
    document.all.spanMessage.style.display = "block";
    if (status) {
        document.all.spanMessage.innerText = "Data was successfully updated!";
        if (instanceCommandType == "delete" || instanceCommandType == "insert")
             location.href="Customers.aspx";
    } else {
        document.all.spanMessage.innerText = "Data was NOT successfully updated!";
    }
    document.all.tblCustomerData.style.display = "none";
    ChangeCursor("default");
}

function ChangeCursor(style) {
    document.body.style.cursor = style;
}


.................................................. ..........
i want to update only one of the cell in datagrid not in different table... hope u can help me..

ashfaq
 
Old April 11th, 2005, 04:47 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It may not be present in the .NET framework, but you can still use it in .NET 1.x. You can even do it in classic ASP, as all you need is a XmlHttp object and some client side JavaScript.

I haven't read all of your code as I found it a bit too much to digest, but did you check out articles like this: http://authors.aspalliance.com/thyco...view.aspx?id=1

Cheers,

Imar





Similar Threads
Thread Thread Starter Forum Replies Last Post
F5 (Refresh) adds a new record after postback krainov BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 November 20th, 2007 10:10 AM
Page Refresh on first postback slim182 ASP.NET 2.0 Basics 4 February 20th, 2007 08:22 PM
Custom Postback and Gridview refresh wirerider ASP.NET 2.0 Basics 5 February 28th, 2006 04:33 PM
Refresh DataGrid without PostBack Baby_programmer Classic ASP XML 1 April 2nd, 2005 04:22 AM
Refresh a combobox without postback Eddy ASP.NET 1.x and 2.0 Application Design 1 March 10th, 2004 12:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.