放动态生成GridView控件到特定< DIV>在ASP.Net C# [英] Put Dynamically Generated GridView to Specific <div> in ASP.Net C#

查看:114
本文介绍了放动态生成GridView控件到特定< DIV>在ASP.Net C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了后面的C#文件代码的GridView

I have created gridview in code behind file of C#.

我要那个GridView控件放置到指定的< DIV> 源文件

I want to place that gridview into a specific <div> of source file.

我的代码来生成网格是:

My code to generate the grid is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class gv1 : System.Web.UI.Page
{
    SqlConnection cn;
    SqlCommand cmd;
    DataSet ds;
    SqlDataAdapter da;

    protected void Page_Load(object sender, EventArgs e)
   {
        cn = new SqlConnection("Data Source=AMIR-PC\\MOHEMMAD;Initial Catalog=CRM_InvestPlus;Integrated Security=True");

   }
   protected void Button1_Click(object sender, EventArgs e)
   {
       cn.Open();
       string query = "select V.Version_Name,S.Software_Name,C.Capacity,V.Price from " +
        "Software_Master S inner join Version_Master V inner join Dealer_License_Capacity C " +
        "on V.Version_ID=C.Version_ID and V.Software_ID=C.Software_ID on " +
        "S.Software_ID=C.Software_ID where C.ID='D00001' and C.Software_ID='001' and C.Version_ID='1'";

    cmd = new SqlCommand(query, cn);
    da = new SqlDataAdapter(cmd);
    ds = new DataSet();
    da.Fill(ds);
    cn.Close();

    GridView gr1 = new GridView();
    Table t = new Table();
    gr1.Controls.Add(t);



    int count = Convert.ToInt32(ds.Tables[0].Rows[0]["Capacity"].ToString());

    for (int i = 0; i < count; i++)
    {

        GridViewRow row = new GridViewRow(i, i, DataControlRowType.DataRow, DataControlRowState.Normal);
        TableCell cell1 = new TableCell();
        TableCell cell2 = new TableCell();
        TableCell cell3 = new TableCell();
        TableCell cell4 = new TableCell();


        TextBox txtPrice = new TextBox();

        FileUpload fl = new FileUpload();
        fl.ID = "fl" + i;


        if (i == 0)
        {
            cell1.Text = ds.Tables[0].Rows[0]["Software_Name"].ToString();
            cell2.Text = ds.Tables[0].Rows[0]["Version_Name"].ToString();
            //cell3.Text = ds.Tables[0].Rows[0]["Price"].ToString();
            cell3.Controls.Add(txtPrice);
        }
        else
        {
            cell1.Text = "";
            cell2.Text = "";
            cell3.Text = "";
        }



        cell4.Controls.Add(fl);

        row.Cells.Add(cell1);
        row.Cells.Add(cell2);
        row.Cells.Add(cell3);
        row.Cells.Add(cell4);

        gr1.Controls[0].Controls.AddAt(i, row);



    }
    form1.Controls.Add(gr1);
   }
}



成功生成网格...

Grid is generated successfully...

现在我想给电网GR1的地方< DIV CLASS =块边界> 标签是:

Now I want to place the grid gr1 to <div class="block-border"> tag that is:

 <div class="grid_6">   
        <div class="container_12">
            <div class="block-border">



这怎么可能放置在GR1最后大多数< DIV> .. ???

请帮忙提前结果
的感谢。

Please help
thanks in advance.

推荐答案

您需要=服务器和一个ID添加到您的div标签,你可以做这样的

you need to add runat="server" and an id to your div tag and you can do it like this

<div id="block" runat="server" class="block-border">

block.Controls.Add(gr1);

这篇关于放动态生成GridView控件到特定&LT; DIV&GT;在ASP.Net C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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