Как я могу экспортировать GridView. DataSource к таблице данных или набору данных?

Следуйте этой статье, чтобы разработать приложение с использованием экспресс-маршрутизатора.

https://scotch.io/tutorials/learn-to-use-the-new-router-in-expressjs-4 [ 112]

определите ваш контроллер следующим образом

exports.index = function(req, res, next) {
  Contact.get(function(err, contacts) {
    if (err) {
      next(null,{
        status: "error",
        message: err
      });
    }

    next({
      status: "success",
      message: "Contacts retrieved successfully",
      data: contacts
    },null);
  });
};

Определите основной файл приложения следующим образом

var contactController = require('./contactController');
    var router = express.Router();
    // apply the routes to our application
    // route middleware that will happen on every request
    router.use(function(req, res, next) {
        // continue doing what we were doing and go to the route
        next(); 
    });

    // about page route (http://localhost:8080/about)
    router.get('/contacts', function(req, res) {
        //here you can call your controller js method
        contactController.index(req,res, function(data, err){
            //change anything you want here and set into res.
            if(err){
              //change status and data
            }
            else{
               //change status and data 
            }
         })
    });

40
задан Soner Gönül 17 October 2011 в 12:20
поделиться

2 ответа

Предполагая, что ваш DataSource имеет тип DataTable, вы можете просто сделать это:

myGridView.DataSource as DataTable
48
ответ дан 27 November 2019 в 01:14
поделиться

Personally I would go with:

DataTable tbl = Gridview1.DataSource as DataTable;

This would allow you to test for null as this results in either DataTable object or null. Casting it as a DataTable using (DataTable)Gridview1.DataSource would cause a crashing error in case the DataSource is actually a DataSet or even some kind of collection.

Supporting Documentation: MSDN Documentation on "as"

19
ответ дан 27 November 2019 в 01:14
поделиться
Другие вопросы по тегам:

Похожие вопросы: