I have a gridview that shows all items under an order. I also have a Textbox I add for the user to add quantity. When they hit enter on that textbox it should run my writeTransaction.
Here is what the Gridview looks like:
Here is my code for my transaction:
protected void writeTransaction()
{
DateTime todaysDate = DateTime.Now;
GridViewRow row = pickListGridview.SelectedRow;
TextBox trQty = row.FindControl("TextBox1") as TextBox;
string unitMeasure = row.Cells[6].Text;
string itemNum = row.Cells[1].Text;
string location = row.Cells[7].Text;
string ordNum = orderNumTextBox.Text.ToUpper();
OleDbCommand cmdWrite = new OleDbCommand("INSERT INTO TRDATA (ACREC, ACSEQ, ADJDT, ADJTM ,APCOD, APHMS, APRJC, BADGE, BLKSQ, CONO, CRWYN, CTLID, EFFIC, ENTUM, " +
"EXFLG, FDATE, IPLOC, ITNBR, LBTIM, LCQC2, LINSQ, LLOCN, LNKNO, LPQC1, MATIM, MSCST, MSQTY, MUCST, MUQTY, ODUDT, ORDNO, PARNT, PLIST, PNREF, QCNTR, QPIEC, QUEUE," +
" RJQTY, RLIST, RNREF, RSUPF, SCRAP, SDATE, SELYN, SEQNM, SHFTC, TCOST, TDATE, TRAMT, TRFMT, TRNA2, TRNN2, TRNC2, TRNNO, TRNNOO, TRQTY, TSTAT, TSTATS, TTIME, TURFA, " +
"TURFN, TURFC, TURNA, TURNN, TURNC, USER2, VRQTY, TRFG, ESHR, WTSK) " +
$"VALUES('Y', '0', '0', '0', 'I', '0', '0', '4153', '0', '0', 'N', '*', '0', '{unitMeasure}', '0', '1141208', '1', '{itemNum}', '0', '0', '0', '{location}', '0', '0', " +
$"'0', '0', '0', '0', '0', '0', '{ordNum}', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '29', '1', '0', '1171103', '0', 'IP', '0'," +
$" '0', '0', '8888889', '0', '{trQty.ToString()}', '2', '0', '85409', '0', '0', '0', '2', '8728517', '5', 'PPL000000017017', '0', '0', '0', '0')", cnTrData);
cnTrData.Open();
cmdWrite.ExecuteNonQuery();
cnTrData.Close();
}
Here is my code for my gridview
<asp:GridView ID="pickListGridview" runat="server" class="hoverTable" OnRowDataBound="pickListGridview_DataBound" OnSelectedIndexChanged="OnSelectedIndexChanged" OnRowCreated="deleteCol" >
<Columns>
<asp:TemplateField HeaderText="QTY">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text="" Width="60px" onkeypress="return EnterEvent(event)" ReadOnly="true"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="25px" HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Here is the javascript that runs the ENTER key command which fires the Save button click event.
<script type="text/javascript">
function EnterEvent(e) {
if (e.keyCode == 13) {
__doPostBack('<%=saveButton.UniqueID%>', "");
}
}
</script>
Here is my click event
protected void saveButton_Click(object sender, EventArgs e)
{
//Response.Write("<script>alert('You have overpicked! This is just a warning!');</script>");
writeTransaction();
}
I know the ENTER button click event fires fine because when I do that and uncomment the Response.Write it fires just fine. I think the issue is lying in the transaction piece because I get an Object not found. Is that SelectedRow the right way to do that? I can do a foreach for the entire gridview and it works fine but I want to do it line by line. Any help would be appreciated!