当我们不知道字段时动态MVC网格 [英] Dynamic MVC Grid when we do not know the fields

查看:59
本文介绍了当我们不知道字段时动态MVC网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当列没有修复时,任何人都知道如何生成网格意味着我们通过MVC不知道我们的表中的字段,请帮我在同一个

Any one know how to generate grid when columns are not fixed means we do not have knowledge of fields in our table through MVC, Please help me in same

推荐答案

你能否更具体一点?

如果你指的是如何将列添加到DataGridView,你不知道列是什么,它会看起来像这样;



Could you please be more specific?
If you're referring to how to add columns to a DataGridView where you don't know what the columns would be, it would look something like this;

private void Form1_Load(object sender, EventArgs e)
{
    try
    {
        DataGridViewColumn column;
        DataGridViewCell cell = new DataGridViewTextBoxCell();
        for (int i = 0; i < 5; i++)
        {
            column = new DataGridViewColumn();
            column.Name = "column" + (i+1).ToString();
            column.HeaderText = "Column " + (i+1).ToString();
            column.ValueType = typeof(string);
            
            column.CellTemplate = cell;

            dataGridView1.Columns.Add(column);
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}





注意:如果您要动态添加列,请确保列在尝试添加之前不存在。



NOTE: If you're going to be adding columns dynamically, make sure the column doesn't already exist before trying to add it.


这篇关于当我们不知道字段时动态MVC网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆