Nach Portierung von ASP.net 2 auf 4.0 funktioniert Gridview nicht mehr



  • Hallo zusammen,

    meine Website läuft nun unter .NET 4.0.
    Das Gridview macht nun allerding nur Scheisse.
    Zuvor gab es in den einzelnen Zeilen des Gridviews keine editierbaren Felder, da es einen extra Bereich zum Editieren gibt.
    Im Gridview würde dadurch das ganze Layout zerstört werden.

    Nun ist es allerdings so, dass nachdem man einen Datensatz (im eigenen Editierbereich) bearbeitet hat, plötzlich eine leere editierbare Zeile im Gridview dargestellt wird.
    Hier wäre ein Ausschnitt des Gridviews aus der aspx-Seite

                        
                        <asp:GridView ID="Gv_Condition" runat="server" AutoGenerateColumns="False" HtmlEncode="False" CellPadding="4" Font-Size="11pt" ForeColor="#333333" 
                            OnRowDataBound="GridView1_RowEvent" GridLines="None" EmptyDataText="Keine Daten gefunden" 
                            OnSorting="GridView1_Sorting" AllowSorting="True" HorizontalAlign="Left" Width="830px" 
                            OnRowEditing="Gv_Condition_RowEditing" AllowPaging="True" 
                            OnPageIndexChanging="Gv_Condition_PageIndexChanging" PageSize="30">
                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <Columns>
                                <asp:BoundField DataField="machine_id" HeaderText="ID" SortExpression="ID" Visible="False" >
                                    <ItemStyle HorizontalAlign="Center" Font-Size="10pt" />
                                    <HeaderStyle Font-Size="10pt" HorizontalAlign="Center" Wrap="False" />
                                </asp:BoundField>
                                <asp:BoundField DataField="condition_id" HeaderText="Interne ID" SortExpression="condition_id" NullDisplayText=" " Visible="True">
                                    <ItemStyle Font-Size="10pt" />
                                    <HeaderStyle Font-Size="10pt" HorizontalAlign="Center" />
                                </asp:BoundField>
    

    Hier wäre die C# Seite dazu:

    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;
    
    public partial class ADMzustand : System.Web.UI.Page
    {
        private DBConnection DBconn = new DBConnection();
        private CustomerBO customerBO;
        private ConditionBC conditionBC = new ConditionBC();
        private MachineBC machineBC = new MachineBC();
        private static DataTable sortDT = null;
        private static string lastSorted = SortDirection.Ascending.ToString();
        private static string idToDelete = "";
        private bool deleteResp = false;
        protected string userCustomer;
    
    
        protected void Page_Load(object sender, EventArgs e)
        {
            //Session Control
            Response.Cache.SetNoStore();
            if (Session["AdminMode"] == null)
                Response.Redirect("login.aspx");
    
            customerBO = (CustomerBO)Session["ADMCustomer"];
            if (customerBO == null)
            {
                Response.Redirect("ADMkundenvowahlen.aspx");
                Context.ApplicationInstance.CompleteRequest();
            }
    
            //Tx_PageIndex.Text = Gv_Condition.PageIndex.ToString();
    
            ((Label)Master.FindControl("Lb_Welcome")).Text = "(ADM) Kunde: " + customerBO.name;
            ((Label)Master.FindControl("Lb_Welcome")).Visible = true;
            userCustomer = customerBO.userCustomer;
            if (!IsPostBack)
            {
                DataTable dt = conditionBC.getCondition("", "", "00010101", "00010101", Tx_QtdItems.Text, customerBO.id);
                Gv_Condition.DataSource = dt;
                Gv_Condition.DataBind();
                sortDT = dt;
            }
            else
            {
                string resp = Request.Form["hdnbox"].ToString();
                if (resp.Equals("Yes"))
                {
                    deleteResp = true;
                }
            }
        }
    
        protected void Bt_Redefine_Click(object sender, EventArgs e)
        {
            this.clearPanel();
            Lb_Erro.Text = "";
    
            DateTime dateFrom = new DateTime();
            DateTime dateUntil = new DateTime();
            if (!Tx_DateFrom.Text.Equals(""))
            {
                dateFrom = conditionBC.getDateFormat(Tx_DateFrom.Text);
            }
            if (!Tx_DateUntil.Text.Equals(""))
            {
                dateUntil = conditionBC.getDateFormat(Tx_DateUntil.Text);
            }
            //Lb_Erro.Text = dateFrom.ToString("yyyy-MM-dd") + " / " + dateUntil.ToString("yyyy-MM-dd");
            //Lb_Erro.Text = conditionBC.getCondition(Tx_InventaryNumber.Text, Tx_MachineName.Text, dateFrom.ToString("yyyy-MM-dd"), dateUntil.ToString("yyyy-MM-dd"), Tx_QtdItems.Text, customerBO.id);
            DataTable dt = conditionBC.getCondition(Tx_InventaryNumber.Text, Tx_MachineName.Text, dateFrom.ToString("yyyyMMdd"), dateUntil.ToString("yyyyMMdd"), Tx_QtdItems.Text, customerBO.id);
            Gv_Condition.DataSource = dt;
            Gv_Condition.PageIndex = 0;
            Gv_Condition.DataBind();
            sortDT = dt;
        }
    
        protected void GridView1_RowEvent(object sender, GridViewRowEventArgs e)
        {
            string rowId = "";
            string rowPhMin = "";
            string rowPhMax = "";
            string rowKonzMin = "";
            string rowKonzMax = "";
            string rowNiMin = "";
            string rowNiMax = "";
            string rowNaMin = "";
            string rowNaMax = "";
            string rowPh = "";
            string rowKonz = "";
            string rowNi = "";
    
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //lRowId = Convert.ToUInt32(e.Row.Cells[0].Text);
                DataRowView rowView = (DataRowView)e.Row.DataItem;
                rowId = rowView["machine_id"].ToString();
                if (rowId != "")
                {
                    DataSet ds = DBconn.executeSelectQuery(QueryRepositorie.getParameterByIdMachine(rowId));
                    DataTable dt = ds.Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                        rowPhMin = dt.Rows[0]["pH_MinLim"].ToString();
                        rowPhMin = rowPhMin.Trim();
                        if (string.IsNullOrEmpty(rowPhMin)) rowPhMin = "0";
                        rowPhMin = rowPhMin.Replace(".", ",");
                        rowPhMax = dt.Rows[0]["pH_MaxLim"].ToString();
                        rowPhMax = rowPhMax.Trim();
                        if (string.IsNullOrEmpty(rowPhMax)) rowPhMax = "0";
                        rowPhMax = rowPhMax.Replace(".", ",");
                        rowKonzMin = dt.Rows[0]["Concentration_MinLim"].ToString();
                        rowKonzMin = rowKonzMin.Trim();
                        if (string.IsNullOrEmpty(rowKonzMin)) rowKonzMin = "0";
                        rowKonzMin = rowKonzMin.Replace(".", ",");
                        rowKonzMax = dt.Rows[0]["Concentration_MaxLim"].ToString();
                        rowKonzMax = rowKonzMax.Trim();
                        if (string.IsNullOrEmpty(rowKonzMax)) rowKonzMax = "0";
                        rowKonzMax = rowKonzMax.Replace(".", ",");
                        rowNiMin = dt.Rows[0]["Nitrite_MinLim"].ToString();
                        rowNiMin = rowNiMin.Trim();
                        if (string.IsNullOrEmpty(rowNiMin)) rowNiMin = "0";
                        rowNiMin = rowNiMin.Replace(".", ",");
                        rowNiMax = dt.Rows[0]["Nitrite_MaxLim"].ToString();
                        rowNiMax = rowNiMax.Trim();
                        if (string.IsNullOrEmpty(rowNiMax)) rowNiMax = "0";
                        rowNiMax = rowNiMax.Replace(".", ",");
                        rowNaMin = dt.Rows[0]["Nitrate_MinLim"].ToString();
                        rowNaMin = rowNaMin.Trim();
                        if (string.IsNullOrEmpty(rowNaMin)) rowNaMin = "0";
                        rowNaMin = rowNaMin.Replace(".", ",");
                        rowNaMax = dt.Rows[0]["Nitrate_MaxLim"].ToString();
                        rowNaMax = rowNaMax.Trim();
                        if (string.IsNullOrEmpty(rowNaMax)) rowNaMax = "0";
                        rowNaMax = rowNaMax.Replace(".", ",");
    
                        rowPh = e.Row.Cells[5].Text;
                        rowPh = rowPh.Trim();
                        if (string.IsNullOrEmpty(rowPh)) rowPh = "0";
                        rowPh = rowPh.Replace(".", ",");
                        rowKonz = e.Row.Cells[6].Text;
                        rowKonz = rowKonz.Trim();
                        if (string.IsNullOrEmpty(rowKonz)) rowKonz = "0";
                        rowKonz = rowKonz.Replace(".", ",");
                        rowNi = e.Row.Cells[7].Text;
                        rowNi = rowNi.Trim();
                        if (string.IsNullOrEmpty(rowNi)) rowNi = "0";
                        rowNi = rowNi.Replace(".", ",");
    
                        //--------------------------------------------------------
                        if (Convert.ToDecimal(rowPh) < Convert.ToDecimal(rowPhMin))
                        {
                            e.Row.Cells[5].ForeColor = System.Drawing.Color.FromName("#f94646");
                        }
                        else if (Convert.ToDecimal(rowPh) > Convert.ToDecimal(rowPhMax))
                        {
                            e.Row.Cells[5].ForeColor = System.Drawing.Color.FromName("#4242ff");
                        }
                        else
                        {
                            e.Row.Cells[5].ForeColor = System.Drawing.Color.FromName("#12b41e");
                        }
                        //--------------------------------------------------------
                        if (Convert.ToDecimal(rowKonz) < Convert.ToDecimal(rowKonzMin))
                        {
                            e.Row.Cells[6].ForeColor = System.Drawing.Color.FromName("#f94646");
                        }
                        else if (Convert.ToDecimal(rowKonz) > Convert.ToDecimal(rowKonzMax))
                        {
                            e.Row.Cells[6].ForeColor = System.Drawing.Color.FromName("#4242ff");
                        }
                        else
                        {
                            e.Row.Cells[6].ForeColor = System.Drawing.Color.FromName("#12b41e");
                        }
                        //--------------------------------------------------------
                        if (Convert.ToDecimal(rowNi) < Convert.ToDecimal(rowNiMin))
                        {
                            e.Row.Cells[7].ForeColor = System.Drawing.Color.FromName("#f94646");
                        }
                        else if (Convert.ToDecimal(rowNi) > Convert.ToDecimal(rowNiMax))
                        {
                            e.Row.Cells[7].ForeColor = System.Drawing.Color.FromName("#4242ff");
                        }
                        else
                        {
                            e.Row.Cells[7].ForeColor = System.Drawing.Color.FromName("#12b41e");
                        }
                        //--------------------------------------------------------
                    }
                }
            }
        }
    
        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {
            DataView dv = new DataView(sortDT);
            if (lastSorted == SortDirection.Ascending.ToString())
            {
                dv.Sort = e.SortExpression + " " + "DESC";
                lastSorted = SortDirection.Descending.ToString();
            }
            else
            {
                dv.Sort = e.SortExpression + " " + "ASC";
                lastSorted = SortDirection.Ascending.ToString();
            }
    
            Gv_Condition.DataSource = dv;
            Gv_Condition.DataBind();
        }
        
        protected void Gv_Condition_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView gv = (GridView)sender;
            GridViewRow gvr = gv.Rows[e.NewEditIndex];
    
            Pn_UpdateCondition.Visible = true;
    
            TableCell tc = gvr.Cells[0];
    
            tc = gvr.Cells[1];
            Lb_InventaryNumber.Text = "Inventar - Nummer: ";
            Lb_Id.Text = tc.Text;
    
            tc = gvr.Cells[4];
            Tx_Datum.Text = tc.Text;
            Tx_Datum.Text = Tx_Datum.Text.Trim();
    
            tc = gvr.Cells[5];
            Tx_pH.Text = tc.Text;
            Tx_pH.Text = Tx_pH.Text.Trim();
    
            tc = gvr.Cells[6];
            Tx_Concentration.Text = tc.Text;
            Tx_Concentration.Text = Tx_Concentration.Text.Trim();
    
            tc = gvr.Cells[7];
            Tx_Nitrit.Text = tc.Text;
            Tx_Nitrit.Text = Tx_Nitrit.Text.Trim();
    
    
            tc = gvr.Cells[8];
            Tx_Nitrat.Text = tc.Text;
            Tx_Nitrat.Text = Tx_Nitrat.Text.Trim();
    
            tc = gvr.Cells[9];
            Tx_Kss.Text = tc.Text;
            Tx_Kss.Text = Tx_Kss.Text.Trim();
    
            tc = gvr.Cells[10];
            Tx_Oil.Text = tc.Text;
            Tx_Oil.Text = Tx_Oil.Text.Trim();
            
    
            tc = gvr.Cells[11];
            Tx_Notes.Text = tc.Text;
            Tx_Notes.Text = replaceSpecialChar(Tx_Notes.Text);
            
    
            //Tx_Notes.Text = replaceSpecialChar("s");
    
            Gv_Condition.SelectedIndex = e.NewEditIndex;
    
        }
    
    
        private string replaceSpecialChar(string line)
        {        
            string newLine = "";
            bool flagChar = false;
            string asciiCode = "";
    
            newLine = line;
    
            for (int i = 0; i < line.Length; i++)
            {
                if (line[i].Equals('&') && line[i+1].Equals('#'))
                {
                    flagChar = true;
                }
    
                if (flagChar)
                {
                    asciiCode = asciiCode + line[i].ToString();
                }
    
                if (line[i].Equals(';') && flagChar)
                {
                    flagChar = false;
    
                    //get the ascII code
                    string asciiStr = asciiCode.Replace("#", "");
                    asciiStr = asciiStr.Replace("&", "");
                    asciiStr = asciiStr.Replace(";", "");
                    char c = (char)Int32.Parse(asciiStr);
                    
                    //replace in the line                
                    newLine = newLine.Replace(asciiCode, c.ToString());
    
                    asciiCode = "";
                }
            }        
            return (newLine);
    
        }
    
        protected void Bt_Update_Click(object sender, EventArgs e)
        {
            string id = Lb_Id.Text;
    
            string date = conditionBC.invertDate(Tx_Datum.Text);
            string result = conditionBC.updateCondition(id, date, Tx_pH.Text.Replace(",", "."), Tx_Concentration.Text.Replace(",", "."), Tx_Nitrit.Text.Replace(",", "."), Tx_Nitrat.Text.Replace(",", "."), Tx_Kss.Text, Tx_Oil.Text, Tx_Notes.Text);
    
            if (result.Equals("1"))
            {
                Lb_Erro.Text = "Record updated";
                Bt_Redefine_Click(null, null);     // warum sollte das ausgeführt werden???
             //   if (Tx_PageIndex.Text != "")
             //       Gv_Condition.PageIndex = Int32.Parse(Tx_PageIndex.Text);
            }
        }
    
    
        protected void Bn_Delete_Click(object sender, EventArgs e)
        {
            idToDelete = Lb_Id.Text;
            if (deleteResp)
            {
                string resp = conditionBC.deleteCondition(idToDelete);
                if (resp.Equals("1"))
                {
                    Lb_Erro.Text = "Record deleted.";
                    Bt_Redefine_Click(null, null);
                }
            }
        }
    
        private void clearPanel()
        {
            Gv_Condition.SelectedIndex = -1;
            Pn_UpdateCondition.Visible = false;
            Tx_Datum.Text = "";
            Tx_Notes.Text = "";        
            Lb_Id.Text = "";
            Tx_pH.Text = "";
            Tx_Concentration.Text = "";
            Tx_Nitrit.Text = "";
            Tx_Nitrat.Text = "";
            Tx_Oil.Text = "";
            Tx_Kss.Text = "";
        }
        protected void Gv_Condition_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            Gv_Condition.PageIndex = e.NewPageIndex;
            Gv_Condition.DataSource = sortDT;
            Gv_Condition.DataBind();  
        }
    }
    
    

    Kann mir bitte irgend jemand erklären, was da schlimmes vor sich geht.
    Ich versteh hier nix mehr!
    Auch die ganzen Erklärungsversuche auf den Microsoft Seiten sagen darüber nix aus!

    Grüsse
    Helmut



  • Die Sache wird sogar noch schlimmer.
    Wenn ich die Werte editieren will, wird auf meinem Entwicklungssystem im Anschluss sogar der Datensatz gelöscht.
    (Nachtrag: Das stimmte nicht. Es war ein NULL-Wert Prolem)
    Das Gridview zeigt dann den nachfolgenden Datensatz in seinen editierbaren Feldern an.

    Wenn ich im Debugger langsam durchsteppe, wird er nicht gelöscht.
    Aber die Zellen des Gridview zeigen den gewählten Datensatz in den editierbaren Feldern an.

    Auf dem Server (IIS 😎 löschte er den Datensatz zum Glück nicht.
    Aber trotzdem wird der gewählte Datensatz im editierbaren Modus im Gridview angezeigt.

    Ich gehe hier definitiv von einem groben Fehler bei Microsoft aus!

    Weiss den wirklich niemand etwas dazu???



  • @elmut19 sagte in Nach Portierung von ASP.net 2 auf 4.0 funktioniert Gridview nicht mehr:

    Ich gehe hier definitiv von einem groben Fehler bei Microsoft aus!

    Wenn Du dieser Meinung bist ... warum gehst Du dann nicht direkt in ein MSDN-Forum und fragst bei MS?



  • Das habe ich doch.
    Da gibts auch keine Antwort.
    Ich suche weiter.
    Nach über 3 Wochen ist man einfach verzweifelt.
    Ausserdem hatte ich schon noch viel mehr Probleme mit de Portierung.
    Sorry.



  • @elmut19 sagte in Nach Portierung von ASP.net 2 auf 4.0 funktioniert Gridview nicht mehr:

    Das habe ich doch.

    Dann solltest Du vielleicht einen Link dazu hierlassen damit der Thread auch einen Sinn hat falls sich das Problem dort löst. Generell gehört es zum guten Ton mit Link auf Crossposts hinzuweisen.

    @elmut19 sagte in Nach Portierung von ASP.net 2 auf 4.0 funktioniert Gridview nicht mehr:

    Da gibts auch keine Antwort.

    Habt ihr vielleicht einen Support-Vertrag und könnt einen Case aufmachen?



  • @Swordfish
    Hallo Swordfish,

    Das mit dem Crosslink wusste ich nicht.
    Mache ich das nächste mal.
    Einen Supporvertrag gib es natürlich auch nicht.
    Aber wenn ein Problem gelöst ist, woher auch immer, dann setze ich die Lösung auch in die anderen Threads.

    Aber inzwischen bin ich selbst einen Schritt weiter gekommen.
    Habe wohl auch etwas treffendere Suchbegriffe verwendet.
    Z.B.: https://social.msdn.microsoft.com/Forums/windows/en-US/7471dd6e-aced-4131-875b-ff2c645adbd9/how-to-disable-editing-in-the-existing-rows-in-a-datagridview-and-allow-the-user-to-add-new-row-to?forum=winformsdatacontrols

        
        protected void Gv_Condition_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView gv = (GridView)sender;
            GridViewRow gvr = gv.Rows[e.NewEditIndex];
            e.Cancel = true;
    
            Pn_UpdateCondition.Visible = true;
    
            TableCell tc = gvr.Cells[0];
    
            tc = gvr.Cells[1];
    .....
    

    Ich habe das "e.Cancel = true;" in die Function reingesetzt.
    Nun geht es wieder.

    Es ist schon sau blöd, wenn gleich drei Fehler hintereinander geschaltet sind.
    Zunächst hatte ich nur Angaben für die Definition des Gridview im aspx gefunden, wo nur der Parameter AutoGenerateColumns="False" angegeben wurde.
    Und auch lange Zeit nichts weiter dazu.
    Das hatte wohl unter .net 2.0 gereicht.

    Warum sich Microsoft keine besseren und von vornherein eindeutigere Definitionen und Funktionen einfallen lässt bleibt mir schleierhaft.

    Vielen Dank noch an alle, die sich durch meine Quelltexte gelesen hatten.

    Grüsse
    Helmut


Anmelden zum Antworten