我可以在运行时设置Gridview的这些属性吗? [英] Can I set these properties of Gridview at run time.

查看:71
本文介绍了我可以在运行时设置Gridview的这些属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用(LinkBut​​ton-Text,CommandName,Onclick等)设置列,TemplateFied,HeaderTemplate,ItemTemplate
我在这里显示代码t_name表名,它是可变的,我想设置
各个表包含各个字段,然后我要使用上述属性生成动态Gridview.

I want to set colums, TemplateFied,HeaderTemplate,ItemTemplate with (LinkButton-Text,CommandName,Onclick etc)
Here I am showing my code t_name table name it is varable,I want to set
various table contains various field,Then I want generate Dynamically Gridview with the above properties.

string str = System.Configuration.ConfigurationManager.ConnectionStrings["sql"].ConnectionString;
        SqlConnection con = new SqlConnection(str);
        SqlCommand cmd;
        SqlDataAdapter ad = new SqlDataAdapter();
        con.Open();
        cmd = new SqlCommand("select * from t_name", con)
        ad.SelectCommand = cmd;
        DataSet ds = new DataSet();
        ad.Fill(ds, t_name);
            GridView1.DataSource = ds;
            GridView1.DataBind();

推荐答案


或者,您可以通过
THIS [ ^ ]

如果有帮助,请 投票 接受答案 .
THIS[^] will show you the Use of Template field in gridview.

Or you could have some further understanding with THIS[^]

Please vote and Accept Answer if it Helped.


这篇关于我可以在运行时设置Gridview的这些属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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