顯示具有 Gridview 標籤的文章。 顯示所有文章
顯示具有 Gridview 標籤的文章。 顯示所有文章

2012年12月4日 星期二

加總GridView內某欄位


dim  count as integer
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
'個人習慣將要加的欄位轉成template
 If e.Row.RowType = DataControlRowType.DataRow Then   
   dim countval as label = e.Row.FindControl("加總欄位id") 
   count += CType(countval.Text, Integer)
 elseIf e.Row.RowType = DataControlRowType.Footer Then
   e.Row.Cells(0).Text = "總分:"
   e.Row.Cells(1).Text = count  
 end if

end sub

2012年11月2日 星期五

RadioButton 使用javascript 在Gridview 中單選





//GridView OnRowDataBound
protected void grid_view_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                RadioButton rb = (RadioButton)e.Row.FindControl("RadioButton1");
                rb.Attributes.Add("onclick", "judge(this)");//給RadioButton加onclick屬性
            }
        }

GridView合併欄位


//GridView合併欄位 GridView加入OnPreRender事件
i =Rows ;j = Columns; Cells =

protected void grid_view_PreRender(object sender, EventArgs e)
        {
            for (int j = 2; j < 3; j++)
            {
                int i = 1;
                foreach (GridViewRow wkItem in grid_view.Rows)
                {
                    if (Convert.ToInt32(wkItem.RowIndex) == 0)
                    {
                        wkItem.Cells[j].RowSpan = 1;
                        wkItem.Cells[j+1].RowSpan = 1;
                    }
                    else
                    {
                        //if (wkItem.Cells[j].Text.Trim() == grid_view.Rows[Convert.ToInt32(wkItem.RowIndex) - i].Cells[j].Text.Trim())
                        if (((Label)wkItem.FindControl("lblGUAR_NM")).Text.Trim() == ((Label)grid_view.Rows[Convert.ToInt32(wkItem.RowIndex) - i].FindControl("lblGUAR_NM")).Text.Trim())
                        {
                            grid_view.Rows[Convert.ToInt32(wkItem.RowIndex) - i].Cells[j].RowSpan += 1;
                            grid_view.Rows[Convert.ToInt32(wkItem.RowIndex) - i].Cells[j+1].RowSpan += 1;
                            i = i + 1;
                            wkItem.Cells[j].Visible = false;
                            wkItem.Cells[j+1].Visible = false;
                        }
                        else
                        {
                            grid_view.Rows[Convert.ToInt32(wkItem.RowIndex)].Cells[j].RowSpan = 1;
                            grid_view.Rows[Convert.ToInt32(wkItem.RowIndex)].Cells[j+1].RowSpan = 1;
                            i = 1;
                        }
                    }
                }
            }
        }

GridView RaidoButon Group 不複選


//RadioButton加入事件
 OnCheckedChanged="RadioButton_CheckedChanged"  AutoPostBack="true"


//RadioButton 事件CheckedChanged
protected void RadioButton_CheckedChanged(object sender, EventArgs e)
        {
            string RadioNowGUAR_SYSID = ((Label)((RadioButton)sender).NamingContainer.FindControl("lblGUAR_SYSID")).Text; //抓取當下RadioButton
            string RadioNowACCT_DATA = ((Label)((RadioButton)sender).NamingContainer.FindControl("lblACCT_DATA")).Text; //抓取當下RadioButton
            string tempGUAR_SYSID,tempACCT_DATA;
            foreach (GridViewRow item in grid_view.Rows)  //此為檢查是否有相同Group
            {
                if (((RadioButton)item.FindControl("RadioButton2")).Checked == true) //此為檢查是否為同Group
                {
                    tempGUAR_SYSID = ((Label)item.FindControl("lblGUAR_SYSID")).Text;
                    tempACCT_DATA = ((Label)item.FindControl("lblACCT_DATA")).Text;
                    if (tempGUAR_SYSID == RadioNowGUAR_SYSID)
                    {
                        if (tempACCT_DATA != RadioNowACCT_DATA)
                        {
                            ((RadioButton)item.FindControl("RadioButton2")).Checked = false;
                        }
                    }
                }
            }
           
        }

以ViewState建立GridView


以ViewState建立Table 並建立新欄位


  if (this.ViewState["tempCUST"] == null)
            {
                DataTable tempdt = new DataTable();
                tempdt.Columns.Add("BORROWER_NM");
                tempdt.Columns.Add("GUAR_NM");
                tempdt.Columns.Add("ACCT_DATA");
                tempdt.Columns.Add("ACCT_DATA2");
                tempdt.Columns.Add("GUAR_SYSID");
                //tempdt.Rows.Add(tempdt.NewRow());
                this.ViewState["tempCUST"] = tempdt;
            }




string returnValue = this.returndata.Value;   //某個Table轉字串接過來
string[] arrreturnValue = returnValue.Split(';'); //分割符號



  DataTable dt = (DataTable)ViewState["tempCUST"];

            foreach (string item in arrreturnValue)
            {
                if (!string.IsNullOrEmpty(item))
                {
                    string[] arrItem = item.Split(',');
                    string strBORROWER_NM = arrItem[0];
                    string strGUAR_NM = arrItem[1];
                    string strACCT_DATA = arrItem[2];
                    string strACCT_DATA2 = arrItem[3];
                    string strGUAR_SYSID = arrItem[4];


                    DataColumn dc = new DataColumn();
                    DataRow dr = dt.NewRow();
                    dr["BORROWER_NM"] = strBORROWER_NM;
                    dr["GUAR_NM"] = strGUAR_NM;
                    dr["ACCT_DATA"] = strACCT_DATA;
                    dr["ACCT_DATA2"] = strACCT_DATA2;

                    dr["GUAR_SYSID"] = strGUAR_SYSID;
                    dt.Rows.Add(dr);

                }
            }
            ViewState["tempCUST"] = dt;
            this.grid_CustW03.DataSource = dt;
            this.grid_CustW03.DataBind();