我们可以在ASP .NET C中没有任何数据的情况下定义动态gridview# [英] Can we define dynamic gridview without any data in ASP .NET C#

查看:64
本文介绍了我们可以在ASP .NET C中没有任何数据的情况下定义动态gridview#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有文本框控件,其中用户插入值即4

然后它将创建大小为4 * 4的gridview,即gridview与

4行和4列

如果用户插入5然后它将创建大小为5行和5列的网格视图

等等

其中不包含任何数据



我的尝试:



我没有任何想法这个

I have textbox control in which User Insert values i.e 4
then It will create gridview of size 4*4 i.e gridview with
4 rows and 4 columns
if User insert 5 then it will create grid view with size 5 rows ans 5 columns
and so on
which does not contain any data in it

What I have tried:

I dont have any Idea about this

推荐答案

试试



try

<asp:TextBox runat="server" ID ="txtCount" />
      <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        <asp:GridView ID="GridView1" runat="server"></asp:GridView>







protected void Button1_Click(object sender, EventArgs e)
      {
          DataTable dt = new DataTable();
          int count = 0;
          int.TryParse(txtCount.Text.Trim(), out count);
          for (int i = 1; i <= count; i++)
              dt.Columns.Add(i.ToString());
          for (int i = 0; i < count; i++)
              dt.Rows.Add(dt.NewRow());

          GridView1.DataSource = dt;
          GridView1.DataBind();


      }


这篇关于我们可以在ASP .NET C中没有任何数据的情况下定义动态gridview#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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