my requirement ,when i input cheque amount in (500) and Cheque No (123), then i press button of adjust amount,
500 amount auto adjust below gridview ,if Amount and Cheque amount is equal then Status will be Received other wise Pending.
From my understanding, you want a function that could automatically fill the cheque amout into each row of below table until the amount reach the receivables (I_Amt).
I constructed a demo but added some change to your codes.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Object reference not set to an instance of an object.
while (cheq_amt_balance > 0)
Line 91: {
Line 92: IEnumerable<DataRow> drs = _gridviewDT.Select("C_Status=1");
Line 93: if (drs.Count() != 0)
Line 94: {
Below is code
private static DataTable _gridviewDT;
public static DataTable GridviewDT
{
get
{
if (_gridviewDT is null)
{
_gridviewDT = new DataTable();
_gridviewDT.Columns.Add("I_ID", typeof(int));
_gridviewDT.Columns.Add("I_Amt", typeof(int));
_gridviewDT.Columns.Add("Cheq_Amt", typeof(int));
_gridviewDT.Columns.Add("Cheq_No", typeof(string));
_gridviewDT.Columns.Add("Display_Cheq_Amt", typeof(string));
_gridviewDT.Columns.Add("C_Status", typeof(int));
}
return _gridviewDT;
}
set
{
_gridviewDT = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
loadgv();
}
}
private void loadgv()
{
SqlCommand cmdbno = new SqlCommand("[SP_Inv_Ret_For_Cheque]", con);
cmdbno.CommandType = CommandType.StoredProcedure;
//cmdbno.Parameters.AddWithValue("PID", txtpackno.Text);
SqlDataAdapter adptbno = new SqlDataAdapter(cmdbno);
DataTable GridviewDT = new DataTable();
adptbno.Fill(GridviewDT);
GridView1.DataSource = GridviewDT;
GridView1.DataBind();
cmdbno.Dispose();
con.Close();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridViewRow row = e.Row;
DropDownList ddl = (DropDownList)row.FindControl("C_Status");
DataRowView rowView = (DataRowView)e.Row.DataItem;
ddl.SelectedValue = rowView["C_Status"].ToString();
}
}
protected void btn_Adj_Click(object sender, EventArgs e)
{
string new_cheq_no = chequno.Text;
int cheq_amt_balance = Convert.ToInt32(chqamount.Text);
while (cheq_amt_balance > 0)
{
IEnumerable<DataRow> drs = _gridviewDT.Select("C_Status=1");
if (drs.Count() != 0)
{
DataRow dr = drs.First();
int cheq_amt = Convert.ToInt32(dr["Cheq_Amt"]);
int i_amt = Convert.ToInt32(dr["I_Amt"]);
string display_cheq_amt = dr["Display_Cheq_Amt"].ToString();
string cheq_no = dr["Cheq_No"].ToString();
int add_cheq_amt = 0;
if (cheq_amt_balance >= (i_amt - cheq_amt))
{
add_cheq_amt = i_amt - cheq_amt;
// Here should update database for Status
dr["C_Status"] = 2;
}
else
{
add_cheq_amt = cheq_amt_balance;
}
// Here should update database for Status
dr["Cheq_Amt"] = cheq_amt + add_cheq_amt;
dr["Display_Cheq_Amt"] = display_cheq_amt + "[" + add_cheq_amt.ToString() + "]";
dr["Cheq_No"] = cheq_no + "[" + new_cheq_no + "]";
cheq_amt_balance -= add_cheq_amt;
}
else
{
cheq_amt_balance = 0;
}
}
loadgv();
}
}
}
The simulation of the in-memory database I used is the static property "GridviewDT" not the private one "_gridviewDT". The initialization and modification is completed through the former one "GridviewDT".
Therefore, you have to use "GridviewDT" in your code then the exception will be disappeared.
There are still some places in codes to be improved. You might need to do this after the demo works.
For example, the input should be checked for the cheque number and cheque amount in case the user inputs are not numbers.
Best regards,
Sean
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Line 80: while (cheq_amt_balance > 0)
Line 81: {
Line 82: IEnumerable<DataRow> drs = dt.Select("C_Status=1");
Line 83: if (drs.Count() != 0)
Line 84: {
The C_Status is what I am using to save the payment status for each rows. If the status is 1 then the row is "Received", otherwise, "Pending".
However, the real implementation should be consistent with your design.
I think you don't have this column in your database so what is the similar column to mark the result of the cheque payment?
You could use that column name in your database to map the data in the GridView Control.
Probably you still have concerns about the codes I provided you with, feel free to let me know.
Here is an option that you could post the database schema and we could modify the codes accordingly.
Best regards,
Sean
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
116 Points
274 Posts
Adjust Textbox amount in gridview row ,according to Amount
Jul 09, 2020 07:21 AM|akhterr|LINK
my requirement ,when i input cheque amount in (500) and Cheque No (123), then i press button of adjust amount,
500 amount auto adjust below gridview ,if Amount and Cheque amount is equal then Status will be Received other wise Pending.
Below is image link
https://ibb.co/8zBRjtY
Contributor
2900 Points
852 Posts
Re: Adjust Textbox amount in gridview row ,according to Amount
Jul 09, 2020 09:51 AM|Sean Fang|LINK
Hi akhterr,
From my understanding, you want a function that could automatically fill the cheque amout into each row of below table until the amount reach the receivables (I_Amt).
I constructed a demo but added some change to your codes.
You could refer to below codes.
.aspx Page:
Code behind:
Demo:
Hope this can help you.
Best regards,
Sean
Member
116 Points
274 Posts
Re: Adjust Textbox amount in gridview row ,according to Amount
Jul 09, 2020 04:54 PM|akhterr|LINK
HI Sean.
here is getting null error
Object reference not set to an instance of an object.
while (cheq_amt_balance > 0) Line 91: { Line 92: IEnumerable<DataRow> drs = _gridviewDT.Select("C_Status=1"); Line 93: if (drs.Count() != 0) Line 94: {
Below is code
Contributor
2900 Points
852 Posts
Re: Adjust Textbox amount in gridview row ,according to Amount
Jul 10, 2020 01:44 AM|Sean Fang|LINK
Hi akhterr,
The simulation of the in-memory database I used is the static property "GridviewDT" not the private one "_gridviewDT". The initialization and modification is completed through the former one "GridviewDT". Therefore, you have to use "GridviewDT" in your code then the exception will be disappeared.
There are still some places in codes to be improved. You might need to do this after the demo works.
For example, the input should be checked for the cheque number and cheque amount in case the user inputs are not numbers.
Best regards,
Sean
Member
116 Points
274 Posts
Re: Adjust Textbox amount in gridview row ,according to Amount
Jul 10, 2020 08:45 AM|akhterr|LINK
HI Sean,
giving below error now
Cannot find column [C_Status].
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.EvaluateException: Cannot find column [C_Status].
Source Error:
Line 80: while (cheq_amt_balance > 0) Line 81: { Line 82: IEnumerable<DataRow> drs = dt.Select("C_Status=1"); Line 83: if (drs.Count() != 0) Line 84: {
Contributor
2900 Points
852 Posts
Re: Adjust Textbox amount in gridview row ,according to Amount
Jul 13, 2020 06:57 AM|Sean Fang|LINK
Hi akhterr,
The C_Status is what I am using to save the payment status for each rows. If the status is 1 then the row is "Received", otherwise, "Pending".
However, the real implementation should be consistent with your design.
I think you don't have this column in your database so what is the similar column to mark the result of the cheque payment?
You could use that column name in your database to map the data in the GridView Control.
Probably you still have concerns about the codes I provided you with, feel free to let me know.
Here is an option that you could post the database schema and we could modify the codes accordingly.
Best regards,
Sean