.COM과.NET

Hagi 2012. 7. 10. 18:27

// aspx에서 DropDownList( ddlPeriodType)로   

//D:일별, W:주별, M:월별, Q:분기별, Y:년별(default, D) 선택


private void GenerateGridViewColumn()
{   
GridView1.Columns.Clear();
switch (ddlPeriodType.SelectedValue)
{
case "W":
BindWeekData();
break;
case "M":
BindMonthData();
break;
case "Q":
BindQuarterData();
break;
case "Y":
BindYearData();
break;
default:
BindDayData();
break;
}
BindCommonData();
}


private void BindWeekData()
{
BindYearData();

BoundField bfMonth = new BoundField();
bfMonth.HeaderText = "월";
  bfMonth.DataField = "MONTH";
this.GridView1.Columns.Add(bfMonth);

BoundField bfWeek = new BoundField();
bfWeek.HeaderText = "주";
  bfWeek.DataField = "WEEK";
this.GridView1.Columns.Add(bfWeek);
}

private void BindMonthData()
{
BindYearData();

BoundField bfMonth = new BoundField();
bfMonth.HeaderText = "월";
  bfMonth.DataField = "MONTH";
this.GridView1.Columns.Add(bfMonth);
}

private void BindQuarterData()
{
BindYearData();

BoundField bfQuarter = new BoundField();
bfQuarter.HeaderText = "분기";
  bfQuarter.DataField = "QUARTER";
this.GridView1.Columns.Add(bfQuarter);
}

private void BindYearData()
{
BoundField bfYear = new BoundField();
bfYear.HeaderText = "년";
  bfYear.DataField = "YEAR";
this.GridView1.Columns.Add(bfYear);
}

private void BindDayData()
{
BindYearData();

BoundField bfMonth = new BoundField();
bfMonth.HeaderText = "월";
bfMonth.DataField = "CPMONTH";
this.GridView1.Columns.Add(bfMonth);

BoundField bfDay = new BoundField();
bfDay.HeaderText = "일";
bfDay.DataField = "CPDAY";
this.GridView1.Columns.Add(bfDay);
}

private void BindCommonData()
{
  BoundField bfProdName = new BoundField();
  bfProdName .HeaderText = "상품명";
  bfProdName .DataField = "PRODNAME";
this.GridView1.Columns.Add(bfUpcName);

BoundField bfCurrencyCode = new BoundField();
bfCurrencyCode.HeaderText = "통화코드";
bfCurrencyCode.DataField = "CURRENCYCODE";
this.GridView1.Columns.Add(bfCurrencyCode);

BoundField bfTotCnt = new BoundField();
bfTotCnt.HeaderText = "거래건수";
bfTotCnt.DataField = "TOTCNT";
bfTotCnt.DataFormatString = "{0:#,##0}";
this.GridView1.Columns.Add(bfTotCnt);

this.GridView1.DataBind();
}


(참고)

http://imaxicool.tistory.com/category/%E2%98%9E%20.NET%20%20%EB%B0%94%EC%A7%80?page=3


http://www.dotnetspider.com/resources/21757-add-boundfield-colume-gridview-at-runtime.aspx


http://aspalliance.com/785_CodeSnip_How_to_Create_a_BoundField_Dynamically_Using_GridView