您的位置:首页 > 产品设计 > UI/UE

get row data value& datatable filter & new datatable from datatable

2012-08-03 02:53 495 查看
1. RowDataBound

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

DefaultValue = ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString();

}

}

2. Checkbox CheckedChanged Event

protected void ckbBillable_CheckedChanged(object sender, EventArgs e)

{

GridViewRow row = ((GridViewRow)((CheckBox)sender).NamingContainer);

CheckBox ckbBillable = (CheckBox)row.FindControl("ckbBillable");

Guid accountId = new Guid(gvAccountBillable.DataKeys[row.RowIndex]["account_id"].ToString());

// Filter in datatable

DataRow[] rows = dtAccountBillable.Select("account_id='" + accountId + "'");



//Update in View state Data table

if (rows.Length > 0)

{

rows[0]["is_billable"] = ckbBillable.Checked;

}

//if checkbox is checd, change the row color

if (ckbBillable.Checked)

{

row.CssClass = "SelectRowStyle";

}

else

{

row.CssClass = "";

}

}

3. in the button click event

protected void btnSubmit_Click(object sender, EventArgs e)

{

Guid rootAccountID = new Guid(gvAccount.DataKeys[0]["root_account_id"].ToString());

DataView dvAccountBilllingInfo = dtAccountBillable.DefaultView;

// new table just has id and is_billable columns. These two field values are from datatable dtAccountBillable.

DataTable dtAccountBillingUpdate = dvAccountBilllingInfo.ToTable(true, " id", "is_billable");


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐