如何将字符串值分配给datagridview [英] How to assign string value to datagridview

查看:168
本文介绍了如何将字符串值分配给datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个变量,其中列标题被定义为string.Now我wqant将此字符串变量分配给datagridview ...如何做到这一点?请帮助我... Thanx提前..

I have one variable in which column headers are defined as string.Now I wqant to assign this string variable to datagridview...How to do this?Please help me...Thanx in advance..

推荐答案





问题非常明确。

您可以将变量存储在一个表和asp.net页面的Page_Load()事件,你把它分配给gridview。



数据访问层,你可以这样做: br />
Hi,

The question aint very clear.
You can store your variables in a table and on Page_Load() event of the asp.net page , you cud assign it to the gridview.

Data access layer, you cud do something like:
public DataTable Grid()
{
    SqlDataAdapter da1 = new SqlDataAdapter("select * from Sample.dbo.tblName", xconn);
    DataTable ds = new DataTable();
    da1.Fill(ds);
    return ds;
}





在aspx.cs页面中,你可以做一些像:





And in the aspx.cs page, you cud do somethinmg like:

protected void Page_Load(object sender, EventArgs e)
{
    DAL obj2 = new DAL();
    DataTable dtnew2 = obj2.Grid();
    GridView1.DataSource = dtnew2;
    GridView1.DataBind();


}





现在你将不得不考虑你是怎么回事?存储您的变量,如在表中,或者您是否通过用户的表单获取变量的值,在后一种情况下,您可以调用存储过程和填充。有很多方法,实现取决于场景和需求。



希望它有所帮助。

快乐编码..



regrds

anurag



Now you will have to think whether how will you store your variables, as in a table or do you wana take the values of the variables via a form from the user, in the latter case, you can call a stored procedure and stuffs. There are numerous methods, implementation depends upon scenarios and needs.

Hope it helps.
Happy coding..

regrds
anurag


这篇关于如何将字符串值分配给datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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