|
-
May 19th, 2011, 12:31 AM
#1
Thread Starter
Fanatic Member
call insert through gridview
wits end im hoping to find solution from you guys.
i have a gridview with a few columns, 2 textbox templatefield,1 button template and bound to sqldatasource .
the button template will call the procedure insert_item with parameter (itemid, rcvd_qty, rate).
how can i hook up the insert_item(x,y,z) to the gridview button?
design sample
Learn something new every .001 second. 
-
May 19th, 2011, 01:12 AM
#2
Re: call insert through gridview
Assuming you have added an InsertCommand to you SqlDataSource, then all you need to do is set the CommandName property of your button.
Have a look at this article:
http://www.aspdotnetfaq.com/Faq/How-...ataSource.aspx
Hope that helps!
Gary
-
May 19th, 2011, 01:22 AM
#3
Thread Starter
Fanatic Member
Re: call insert through gridview
@gep13 thanks it seems what im looking.
also i want to add validation on addbutton_click through javascript. i need to meet the conditions
1] Rcvd_Bal <=Bal of the active row
2] Rcvd_Rate <=PO Rate of the active row
Learn something new every .001 second. 
-
May 19th, 2011, 01:35 AM
#4
Re: call insert through gridview
Hello,
In the TemplateField, where you have the TextBoxes, you can also had some Validator Controls. In your case, you won't be able to use an Out of the Box validator, but you could use a CustomValidator.
Gary
-
May 19th, 2011, 02:01 AM
#5
Thread Starter
Fanatic Member
Re: call insert through gridview
great. thanks for the info...let me take this one at a time.
Learn something new every .001 second. 
-
May 19th, 2011, 07:56 AM
#6
Re: call insert through gridview
Sure, just let me know if you have any follow up questions.
Gary
-
May 19th, 2011, 08:17 AM
#7
Thread Starter
Fanatic Member
Re: call insert through gridview
twas a kick ass sample . the insert button works on fly but im getting error when using the value pass from gridview textbox.
Code:
<asp:TemplateField HeaderText="rcvd qty">
<ItemTemplate>
<asp:TextBox runat ="server" ID="rcvdqty_textbox" Text="0" Width="50"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
vb Code:
Dim rcvdqty As TextBox = TryCast(GridView2.Controls(0).Controls(0).FindControl("rcvdqty_textbox"), TextBox) Dim _rcvdqty As New SqlParameter("@rcvdqty", SqlDbType.Float) _rcvdqty.Direction = ParameterDirection.Input 'this line doesnt work and it returns an error 'Object reference not set to an instance of an object. _rcvdqty.Value = rcvdqty.Text insertParameters.Add(_rcvdqty)
heres the grid.
Last edited by jlbantang; May 19th, 2011 at 08:27 AM.
Learn something new every .001 second. 
-
May 20th, 2011, 09:43 AM
#8
Re: call insert through gridview
Hello,
If you set a break point on this line:
Code:
_rcvdqty.Value = rcvdqty.Text
Can you confirm that rcvdqty is null/Nothing?
Gary
-
May 21st, 2011, 12:20 AM
#9
Thread Starter
Fanatic Member
Re: call insert through gridview
hi gary, yes its says nothing.
so this code did not work i assume.
Code:
Dim rcvdqty As TextBox = TryCast(GridView2.Controls(0).Controls(0).FindControl("rcvdqty_textbox"), TextBox)
...still finding sample
from the post#7 screenshot i need to add data under columns rcvdID, grfID, rcvd qty and rcvd rate in the insert command but im not getting the correct row index.
Last edited by jlbantang; May 21st, 2011 at 06:09 AM.
Learn something new every .001 second. 
-
May 21st, 2011, 08:55 AM
#10
Re: call insert through gridview
Hey,
Correct, that line is the problem one.
If FindControl does not find the item that you are looking for, it will return a null/Nothing.
If I were you, I would set a break point on that line, and then start your debugging. i..e what control do you get back when you do this:
Code:
GridView2.Controls(0)
Begin stepping into the code, using the watch window, and I am sure you will figure out what is going on.
Gary
-
May 22nd, 2011, 01:50 AM
#11
Thread Starter
Fanatic Member
Re: call insert through gridview
hey gary, i manage to find a time saver solution from different threads. please let me know if their is a need to revise the code.
vb Code:
If e.CommandName = "insert" Then 'get fired button from gridview container and return as row Dim rowSelect As GridViewRow = DirectCast(DirectCast(e.CommandSource, Button).NamingContainer, GridViewRow) 'get row index Dim rowindex As Integer = rowSelect.RowIndex 'get textbox value using rowindex at col 6 Dim txt As TextBox = DirectCast(GridView2.Rows(rowindex).Cells(6).FindControl("rcvdqty_textbox"), TextBox) 'do the rest End if
thanks.
Learn something new every .001 second. 
-
May 22nd, 2011, 08:05 AM
#12
Thread Starter
Fanatic Member
Re: call insert through gridview
great now i need to perform client validation. 3 rules:
1. rcvd qty is a required field. can be done through required field validation control
2. rcvd qty must be numeric-float in format. can be done through regular expression validation control
3. now comes another issue. i need to compare the rcvd qty with balance qty. its obvious rcvd qty should be always <= balance qty. i used label control for balance qty and textbox for rcvd quantity. having said that it seems the comparison validation control do not support textbox and label comparison. now the work around again to use javascript. simple and easy , call javascript validation function when insert button fires up.
im just wondering why im not getting the value of rcvd textbox during grid iteration. in the page source the rcvd qty has this name GridView3$ctl03$rcvdqty_textbox where ctl03 is the control index. similarly the balance label has this name series GridView3_ctl02_balanceLabel where ctl02 is the control index.
somehow im not getting the value of rcvdqty textbox.
Code:
var thetextbox;
thetextbox=document.getElementById('GridView3_ctl02_rcvdqty_textbox');
alert(thetextbox.innerHTML);
suggestions are open. thanks.
Last edited by jlbantang; May 22nd, 2011 at 08:10 AM.
Learn something new every .001 second. 
-
May 24th, 2011, 01:00 AM
#13
Re: call insert through gridview
Hello,
Change you code slightly to be this:
What do you get?
Gary
-
May 25th, 2011, 09:10 AM
#14
Thread Starter
Fanatic Member
Re: call insert through gridview
hi gary,
got it with this code
thetextbox=document.getElementById('GridView3_ctl02_rcvdqty_textbox').value;
alert(thetextbox);
im doing the other stuff. i'll be back quickly. thanks.
Learn something new every .001 second. 
-
May 26th, 2011, 01:38 AM
#15
Re: call insert through gridview
Cool, looks like you have it.
The reason that I was asking you to do this:
Was to prove that the getElementById was actually finding something. If it wasn't you would have got a null in the alert message. You should have been getting object, the extension from that would have been to again test:
Code:
alert(thetextbox.innerHTML);
If this returned null, then the natural conclusion would have been that the innerHTML property was not available.
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|