在C#中动态生成gridview [英] generate gridview dynamically in c#
问题描述
我想动态生成gridview.
我有两个选择
1)用户可以从复选框列表中选择财务年度,例如2010年4月-2011年3月
2)用户可以使用日历控件选择日期,日期将显示在茶叶盒中.例如1-4-2010至31-8-2010.
如果用户选择复选框列表,则在gridview列中应为4月,5月,6月....jan,feb,march
如果用户在文本框中输入日期,则在gridview列中应为4月,5月,6月,7月,8月.
我不知道该怎么做,我坚持自己的逻辑..
i want to generate gridview dynamically.
i have two options
1) user can select financial year from checkboxlist e.g april 2010 - march 2011
2) user can select date using calender control and date will be displayed in teaxtboxes.. e.g 1-4-2010 to 31-8-2010.
if user selects checkboxlist then in gridview collumn should be april, may,jun.... jan,feb,march
if user enters date in textbox then in gridview column should be april,may,jun,jul,aug.
i don''t know how to do this and i stuck in my logic..
kindly help me out as soon as possible.
推荐答案
您可以根据日期编写查询,并在Sql中创建一个视图并将该视图绑定到Gridview.Hope这将对您有帮助.编程愉快.
You can write a query based on the date and make a view in Sql and Bind this view to the Gridview.Hope this will help you.Happy Programming.
尝试此代码
try this code
SqlConnection myConnection;
string str_Account_Select = "SELECT * FROM AccountsTable where coumnname="+value+"";
SqlCommand myCommand;
DataSet myDataSet;
myConnection = new SqlConnection(connectionString);
myConnection.Open();
myCommand = new SqlCommand(str_Account_Select, myConnection);
SqlDataAdapter mySQLDataAdapter;
myDataSet = new DataSet();
mySQLDataAdapter = new SqlDataAdapter(myCommand);
mySQLDataAdapter.Fill(myDataSet, "AccountsTable");
GridView1.DataSource = myDataSet;
GridView1.DataBind();
}
这篇关于在C#中动态生成gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!