如何获取已存在的数据视图的dataview对象?

时间:2013-10-04 09:31:17

标签: javascript jquery slickgrid dataview

基本上我想将一些数据作为

插入到现有的slickgrid数据视图中
dataView.addItem();

所以,我需要div中的slickgrid数据视图的dataview对象 #myGrid

2 个答案:

答案 0 :(得分:0)

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        string connetionString = null;
        SqlConnection connection ;
        SqlCommand command ;
        SqlDataAdapter adapter = new SqlDataAdapter();
        DataSet ds = new DataSet();
        DataView dv ;
        string sql = null;
        connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password";
        sql = "Select * from product";
        connection = new SqlConnection(connetionString);
        try
        {
            connection.Open();
            command = new SqlCommand(sql, connection);
            adapter.SelectCommand = command;
            adapter.Fill(ds, "Add New");
            adapter.Dispose();
            command.Dispose();
            connection.Close();

            dv = new DataView(ds.Tables[0]);
            DataRowView newRow = dv.AddNew();
            newRow["Product_ID"] = 7;
            newRow["Product_Name"] = "Product 7";
            newRow["Product_Price"] = 111;
            newRow.EndEdit();
            dv.Sort = "product_id";


            dataGridView1.DataSource = dv;
        }
        catch (Exception ex)
        {
            MessageBox.Show (ex.ToString());
        }
    }
}

答案 1 :(得分:0)

试试这个:

要查找数据网格,您必须使用$ .find()

var MyGrid=$.find(<%=myGrid.ClientID%>)