Καλώς ορίσατε στο dotNETZone.gr - Σύνδεση | Εγγραφή | Βοήθεια
σε

 

Αρχική σελίδα Ιστολόγια Συζητήσεις Εκθέσεις Φωτογραφιών Αρχειοθήκες

GridView & RowCommand Event

Îåêßíçóå áðü ôï ìÝëïò m6s. Τελευταία δημοσίευση από το μέλος Markos στις 18-08-2010, 17:14. Υπάρχουν 8 απαντήσεις.
Ταξινόμηση Δημοσιεύσεων: Προηγούμενο Επόμενο
  •  18-08-2010, 03:23 59679

    GridView & RowCommand Event

    Καλησπέρα,

    Εχω ένα gridview. Το datasource είναι ένα linq αποτέλεσμα. Και έχω ένα ButtonField. Όρισα CommandName, και sτο gridview το OnRowCommand είναι "δεμένο" με το event "GridBase1_RowCommand".
    Ότι και να κάνω, όποια παραλαγή ( ακόμα και στον τύπο του Field του ίδιου),
    δεν ενεργοποιείται το event :
    void GridBase1_RowCommand(Object sender, GridViewCommandEventArgs e).

    Το event το έχω στην ίδια την aspx σελίδα, δεν έχω CodeBehind ορίσει.
    Απλά μοιάζει σαν να κάνει ανανέωση την σελίδα...τίποτα άλλο! :-(
    Κάπου σε κάποιο φορουμ διάβασα το EnableViewState να είναι true. Δεν βοήθησε.

    Εδώ είναι το πώς ξεκινάει  η σελίδα :
    <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true"
        Inherits="System.Web.Mvc.ViewPage<IEnumerable<Test.Models.company>>" EnableViewState="true" %>


    Τι κάνω λάθος;

    ( Είναι μέσα σε asp:Content το gridview το οποίο είναι και αυτό μέσα σε ένα form tag. )
  •  18-08-2010, 12:32 59680 σε απάντηση της 59679

    Απ: GridView & RowCommand Event

    Καλημέρα,

    Έχεις κάποια derived κλάση και θέλεις να κάνεις override το OnRowCommand ή θέλεις να εκτέλεσεις ένα command; Τι τιμή έχει το CommandName; Αν πρόκειται για τη δεύτερη περίπτωση, το CommandName παίρνει συγκεκριμένες τιμές και ανάλογα με την τιμή γίνεται raise συγκεκριμένο event.


    Ακόμα κι ένας άνθρωπος μπορεί ν' αλλάξει τον κόσμο. Μη θέλεις να κυβερνήσεις. Απλά δείξε το μονοπάτι κι ο κόσμος θ' ακολουθήσει!!
  •  18-08-2010, 15:02 59682 σε απάντηση της 59680

    Απ: GridView & RowCommand Event

    Καλημέρα Μάρκο,

    Δεν προσπαθώ να κάνω κάτι override θέλω να εκτελέσω ένα event, σε κάθε γραμμή.
    Σκέψου δηλαδή ότι το σενάριο είναι :

    1. Εχω gridview με γραμμές.
    2. Σε κάθε γραμμή έχω ένα κουμπί(ButtonField) ( μπορούσε να είναι και link! αλλά και αυτό μου δημιούργησε θέματα )
    3. Πατώντας το κουμπί, να ανοίξει μια σελίδα, που να έχει και μια τιμή κρατήσει π.χ. το Primary Key της γραμμής που ανήκει το κουμπί.

    Παραθέτω το GridView,  [και πρόσεξε ( αν θές ) ότι δοκίμασα και με templatefield να έχω κουμπί από ένα tutorial της microsoft
    και προσπάθησα να κόψω το PostBack....] :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
     
    <fieldset>
    		<cc2:DataGridBase ID="GridBase1" runat="server" CssClass="grid" AutoGenerateColumns="False"
    			ShowFooter="true" AutoGenerateEditButton="true" OnRowCommand="GridBase1_RowCommand"
    			DataKeyNames="CompanyId, DepartmentId" EnableViewState="true">
    			<Columns>
    				<asp:ButtonField ButtonType="Button" CommandName="Select" HeaderText="Open Web Page"
    					Text="New Webpage">
    					<ControlStyle Font-Size="X-Small" />
    				</asp:ButtonField>
    				<asp:TemplateField>
    					<ItemTemplate>
    						<asp:Button runat="server" ID="IncreaseButton" Text="Increase Price 5%" CommandName="Increase"
    							OnClientClick="return false;" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
    					</ItemTemplate>
    				</asp:TemplateField>
    			</Columns>
    		</cc2:DataGridBase>
    	</fieldset>


    Και εδώ είναι το event το ίδιο :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
     
    void GridBase1_RowCommand(Object sender, GridViewCommandEventArgs e) {
    			// If multiple buttons are used in a GridView control, use the
    			// CommandName property to determine which button was clicked.
    			if ( e.CommandName == "Increase" ) {
    				// Convert the row index stored in the CommandArgument
    				// property to an Integer.
    				int index = Convert.ToInt32(e.CommandArgument);
    
    				// Retrieve the row that contains the button clicked 
    				// by the user from the Rows collection.      
    				GridViewRow row = GridBase1.Rows[index];
    
    				// Calculate the new price.
    				Label listPriceTextBox = (Label)row.FindControl("PriceLabel");
    				listPriceTextBox.Text = (Convert.ToDouble(listPriceTextBox.Text) * 1.05).ToString();
    
    				// Update the row.
    				GridBase1.UpdateRow(index, false);
    			}


    Ελπίζω να βοηθάει η παράθεση μου....


  •  18-08-2010, 15:57 59683 σε απάντηση της 59682

    Απ: GridView & RowCommand Event

    Ερώτηση: Αφού κόβεις το PostBack, πως θα εκτελεστεί το event; Βγάλε το OnClientClick από το button. Επίσης, ρίξε και μια ματιά στο UpdateRow method του GridView για να δεις αν στον κώδικά σου ισχύουν οι προϋποθέσεις που αναφέρονται στο Note:

    "This method can be called only for the row that is currently in edit mode, or for a row that contains a two-way data-bound input control. For more information about two-way binding expressions, see Binding to Databases."


    Ακόμα κι ένας άνθρωπος μπορεί ν' αλλάξει τον κόσμο. Μη θέλεις να κυβερνήσεις. Απλά δείξε το μονοπάτι κι ο κόσμος θ' ακολουθήσει!!
  •  18-08-2010, 16:15 59684 σε απάντηση της 59679

    Απ: GridView & RowCommand Event

    m6s:

    Εδώ είναι το πώς ξεκινάει  η σελίδα :
    <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true"
        Inherits="System.Web.Mvc.ViewPage<IEnumerable<Test.Models.company>>" EnableViewState="true" %>


    Τι κάνω λάθος;

    ( Είναι μέσα σε asp:Content το gridview το οποίο είναι και αυτό μέσα σε ένα form tag. )

    Τα ASP.NET Form controls δεν παίζουν μέσα σε ASP.NET MVC projects => το control που χρησιμοποιείς δεν θα "τρέξει". Οι επιλογές σου είναι είτε να καταφύγεις σε MVC extensions που έχουν φτιαχτεί να κάνουν παρόμοια δουλειά ή να δεις extensions του MVC framework από τρίτους κατασκευαστές που προσφέρουν παρόμοια λειτουργικότητα...

     

    George J.


    George J. Capnias: Χειροπρακτικός Υπολογιστών, Ύψιστος Γκουράρχης της Κουμπουτερολογίας
    w: capnias.org, t: @gcapnias, l: gr.linkedin.com/in/gcapnias
    dotNETZone.gr News
  •  18-08-2010, 16:34 59685 σε απάντηση της 59684

    Απ: GridView & RowCommand Event

    ΩΧ! Σοβαρά;
    Για αυτό παιδεύωμαι τόσο καιρό;
    Παιδιά έχω φάει τέτοια απογοήτευση που δεν προφέρεται!

    Ξεκίνησα δοκιμάζωντας τα infragistics γιατί τα δούλευα σε winform ( και είναι τέλεια εκεί ) , αλλά σε asp.net mvc2 έφαγα πολλά άκυρα.
    Γυρνάω στην λύση την απλή των datagrid/gridview και με τα πολλά έφτασα εδώ.ΩΧ! Μιλάμε για μέρες ακόμα και στην άδεια μου!

    Είναι σίγουρο αυτό;

    Δείτε το κώδικα στο http://pastebin.com/G8G3bAHm , αν γίνεται!
    Εκεί, έχω καταφέρει το DropDownList, σύνδεση με mysql...όλα! Το μόνο που δεν πιάνει είναι το Click!

    Και κερνάω καφέ! Το λιγότερο! :-))
  •  18-08-2010, 16:42 59686 σε απάντηση της 59684

    Απ: GridView & RowCommand Event

    George J. Capnias:

    Τα ASP.NET Form controls δεν παίζουν μέσα σε ASP.NET MVC projects...

    SurpriseΜάλιστα... πιάστηκα αδιάβαστος. Πάντως θα πρέπει να υπάρχει κάποιος τρόπος να προσθέσεις Web Forms σε MVC project.


    Ακόμα κι ένας άνθρωπος μπορεί ν' αλλάξει τον κόσμο. Μη θέλεις να κυβερνήσεις. Απλά δείξε το μονοπάτι κι ο κόσμος θ' ακολουθήσει!!
  •  18-08-2010, 16:53 59687 σε απάντηση της 59686

    Απ: GridView & RowCommand Event

    Τι είναι και τι αφορά τελικά το ASP.NET Form Control και το ASP.NET MVC τότε τι διαφορά έχει;

  •  18-08-2010, 17:14 59688 σε απάντηση της 59687

    Απ: GridView & RowCommand Event

    m6s:
    Τι είναι και τι αφορά τελικά το ASP.NET Form Control και το ASP.NET MVC τότε τι διαφορά έχει;

    Νομίζω ότι όλο το ζουμί βρίσκεται σ' αυτή την παράγραφο από το άρθρο του Dino Esposito (έχω κάνει bold κάποια σημεία):

    "When you write an ASP.NET MVC application, you think in terms of controllers and views. You make your decisions about how to pass data to the view and how to expose your middle tier to the controllers. The controller chooses which view to display based on the requested URL and pertinent data. Each request is resolved by invoking a method on a controller class. No postbacks are ever required to service a user request. No viewstate is ever required to persist the state of the page. No arraysof black-box server controls exist to produce the HTML for the browser.

    With ASP.NET MVC, you rediscover the good old taste of the Web—stateless behavior, full control over every single bit of HTML, total script and CSS freedom.
    The HTML served to the browser is generated by a separate, and replaceable, engine. There's no dependency on ASPX physical server files. ASPX files may still be part of your project, but they now serve as plain HTML templates, along with their code-behind classes. The default view engine is based on the Web Forms rendering engine, but you can use other pluggable engines such as nVelocity or XSLT. (For more details, have a look at the MVCContrib Web site at mvccontrib.codeplex.com.)
    The runtime environment is largely the same as in ASP.NET Web Forms, but the request cycle is simpler and more direct. An essential part of the Web Forms model, the page lifecycle, is no longer necessary in ASP.NET MVC. It should be noted, though, that the default view engine in ASP.NET MVC is still based on the Web Forms rendering engine. This is the trick that allows you to use master pages and some server controls in ASP.NET MVC views. As long as the view engine is based on Web Forms, the view is an ASPX file with a regular code-behind class where you can handle classic events such as Init, Load, PreRender, plus control-specific events such as RowDataBound for a GridView control. If you switch off the default view engine, you no longer need Page_Loador other events of the standard page lifecycle."
     
    Πάντως, σίγουρα μέσω routing μπορείς να βάλεις webforms σε mvc project. Θέλει λίγο διάβασμα.
     

    Ακόμα κι ένας άνθρωπος μπορεί ν' αλλάξει τον κόσμο. Μη θέλεις να κυβερνήσεις. Απλά δείξε το μονοπάτι κι ο κόσμος θ' ακολουθήσει!!
Προβολή Τροφοδοσίας RSS με μορφή XML
Με χρήση του Community Server (Commercial Edition), από την Telligent Systems