からボタンにチェックイン、チェックボックスの値を取得します。コードのボタンのクリックイベントで計算される行私はGridViewのは、生成したGridViewの
protected void CashPayButton_Click(object sender, EventArgs e)
{ }
からボタンにチェックイン、チェックボックスの値を取得します。コードのボタンのクリックイベントで計算される行私はGridViewのは、生成したGridViewの
protected void CashPayButton_Click(object sender, EventArgs e)
{ }
これはあなたの欲しいものですか?
protected void CashPayButton_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in Cash_GridView.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox c = (CheckBox)row.FindControl("MemberCheck");
if (c.Checked)
{
//do calculation with other controls in the row
}
}
}
}
(または、これは動作しませんよりも、計算は、チェックボックスをクリックの上、すぐに起こるはず)
ボタンをクリックしても計算が機能しない –
それはあなたがあなたの計算を行うためにクリックする必要があります唯一のボタンだと仮定すると、次の操作を行うことができます( Loadイベントを使用していることに注意してください)、ボタンをクリックしたときとポストバックが発生したときに呼び出されます。
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
ProcessRows();
}
}
private void ProcessRows()
{
foreach (GridViewRow oneRow in Cash_GridView.Rows)
{
CheckBox checkBoxControl = oneRow.FindControl("MemberCheck") as CheckBox;
if (checkBoxControl != null && checkBoxControl.Checked)
{
// You have a row with a 'Checked' checkbox.
// You can access other controls like I have accessed the checkbox
// For example, If you have a textbox named "YourTextBox":
TextBox textBoxSomething = oneRow.FindControl("YourTextBox") as TextBox;
if (textBoxSomething != null)
{
// Use the control value for whatever purpose you want.
// Example:
if (!string.IsNullOrWhiteSpace(textBoxSomething.Text))
{
int amount = 0;
int.TryParse(textBoxSomething.Text, out amount);
// Now you can use the amount for any calculation
}
}
}
}
}
は、次のコードを使用します(あなたが原因ポストバックのボタンをクリックすると、計算が起こります):
protected void CashPayButton_Click(object sender, EventArgs e)
{
foreach(Gridviewrow gvr in Cash_GridView.Rows)
{
if(((CheckBox)gvr.findcontrol("MemberCheck")).Checked == true)
{
int uPrimaryid= gvr.cells["uPrimaryID"];
}
}
}
foreach (GridViewRow r in GridView1.Rows)
{
if ((r.Cells[2].Controls.OfType<CheckBox>().ToList()[0]).Checked == true)
{
//your code.
}
}
あなたがここで達成しようとしますか?複数のチェックボックスをオンにして計算したいですか? –