I have a seperate column in my gridview and also I have added an checkbox/button. So when an user checks or clicks the checkbox or button it should update my oracle database. When an user checks the checkbox it should take invoices value which is present in the second column and based on that invoice numbers my database should get updated with value 1 for that particular invoice rows
I have added this function. Here I am using button feature.checkbox or button anyone is fine. Here is what I have implemented:
protected void GridViewRemittance_RowCommand(object sender, GridViewCommandEventArgs e) {
if (e.CommandName == "UpdateRow") {
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + e.CommandArgument + "');", true);
string invoiceID = Convert.ToString(e.CommandArgument);
UpdateDatabase(invoiceID);
}
}
protected void UpdateDatabase(string i) {
string invoiceNumber = i;
using (OracleConnection Conn = new OracleConnection(strCon)) {
using (OracleCommand cmd = new OracleCommand()) {
Conn.Open(); cmd.Connection = Conn;
cmd.CommandText = "Update ap_lineitem_staging SET selected_invoice = 1 where pre_invoice_num='" + invoiceNumber + "'";
cmd.ExecuteNonQuery();
}
}
}
2
Answers
try this
I suggest you simply add to the GridView a check box control.
So, in this example, we want to set the Hotel as "Active". (We thus assume we have a column in the database called Active.
So, this GridView markup:
And code behind:
And we now have this:
So, now let’s add an event for the check box in above.
Since we can’t bring up the property sheet for the check box (since it is nested inside of the GridView), then we simply add the event to the check box by using markup.
So, then this:
So, we now have an event code stub for the check box.
Thus, the code behind for the check box then becomes this:
And for completeness, I’ll include my 2 "helper" routines that are global to the application. They are:
In above, I used the DataKeys[] feature of the GridView, as that allows you to use the database primary key value, but does not require you to include or show the database PK value in the GridView.
You can of course use the invoice number in the above SQL update, but in most cases, when possible, I do suggest using the DataKeys feature along with using the database primary key for the update.
In above, I used SQL server syntax and not Oracle syntax, but the over all approach and concept is the same.