Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 2nd, 2007, 07:33 AM
Authorized User
 
Join Date: Oct 2005
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default get value of textbox inside datagrid

hi there,

anyone knows how to get value of the textbox inside datagrid then save it in database,after i tried to get the value of textbox inside datagrid like this but still get error ?

the problem is...when i tried to call the submitReview method from the submit button, it does not get the value from the textbox that generated from datagrid. in my database it get null value....



Code:
Sub submitReview(ByVal sender As Object, ByVal e As EventArgs)


        Dim myConnection As New SqlConnection(Conn)

        '2. Create the command object, passing in the SQL string
        Dim strSQL As String = "SELECT Student.FirstName "
        strSQL += "From Groups, GroupStudent, Subject, Student "
        strSQL += "WHERE ((Groups.groupID = GroupStudent.groupID) "
        strSQL += "AND (Student.SubjectCodeID = Subject.SubjectCodeID) "
        strSQL += "AND (GroupStudent.StudentNo = Student.StudentNo) "
        strSQL += "AND (Groups.SubjectCodeID = Student.SubjectCodeID) "
        strSQL += "AND (Subject.SubjectCodeID = " & Session("StudentSubjectCodeID") & ")"
        strSQL += "AND (Student.SubjectCodeID = " & Session("StudentSubjectCodeID") & ")"
        strSQL += "AND (Groups.GroupID = " & "1" & ")) "




        Dim myCommand As New SqlCommand(strSQL, myConnection)

        '3. Create the DataAdapter
        Dim myDA As New SqlDataAdapter()
        myDA.SelectCommand = myCommand

        '4. Populate the DataSet
        Dim myDS As New DataSet()
        myDA.Fill(myDS)

        Count = myDS.Tables(0).Rows.Count

        Dim queryString2 As String = "SELECT * FROM Result"
        myCommand.CommandText = queryString2

        myDA.SelectCommand = myCommand
        Dim dataSet2 As DataSet = New DataSet

        myDA.Fill(dataSet2)
        Dim usernamecheck As Boolean = False




        Dim item As DataGridItem = dg1.Items(Count - 1)
        'Check for repeated username registration
        For i As Integer = 0 To Count - 1

            mark = DirectCast(item.FindControl("sMark"), TextBox).Text().Trim()
            com = DirectCast(item.FindControl("sCommnet"), TextBox).Text().Trim()

            'Dim firstBCTextBox As TextBox = CType(e.item.Cells(1).Controls(0), TextBox)
            'Dim firstTextBoxValue As String = firstBCTextBox.Text

            'Dim secondBCTextBox As TextBox = CType(e.Item.Cells(2).Controls(0), TextBox)
            'Dim secondTextBoxValue As String = secondBCTextBox.Text


            Dim queryString As String = "Insert Into Result (Comment,Mark,StudentA,StudentB,GroupStudentID,ReportID)" & _
                   " VALUES('" & com & "', '" & mark & "', '" & "9" & "', '" & "9" & "', '" & "1" & "', '" & "3" & "')"


            myCommand.CommandText = queryString
            myCommand.Connection = myConnection

            ' Open the connection, execute the command, and close the connection.

            myConnection.Open()
            myCommand.ExecuteNonQuery()
            myConnection.Close()



        Next
        Server.Transfer("Student_ConfirmSubmitReview.aspx")

    End Sub
---------------- html code -----------------------


Code:
<asp:DataGrid ID="dg1" runat="server">
         <HeaderStyle font-size="10pt" horizontalalign="Center" forecolor="White" backcolor="Black"></HeaderStyle>

                     <Columns>
                            <asp:TemplateColumn HeaderText="Student Name">
                                           <ItemTemplate>
                                                <asp:Label id="sName" runat="server" text='<%# DataBinder.Eval(Container.DataItem, "FirstName")  %>' /> 
                                           </ItemTemplate>
                                         </asp:TemplateColumn>      
                                         <asp:TemplateColumn HeaderText="Mark">
                                           <ItemTemplate>
                                                <asp:TextBox ID="sMark" runat="server"></asp:TextBox>
                                           </ItemTemplate>
                                         </asp:TemplateColumn> 
                                         <asp:TemplateColumn HeaderText="Comment">
                                           <ItemTemplate>
                                                 <asp:TextBox ID="sComment" runat="server" Rows="3" Columns="3" ></asp:TextBox>

                                           </ItemTemplate>
                                         </asp:TemplateColumn>

                      </Columns>

      </asp:DataGrid>          

                        <asp:Button runat="server" ID="subButton" Text="Submit" OnClick="submitReview" />
 
Old October 2nd, 2007, 07:36 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. where is your error?? also if you post some code, could you be kind and clean it up??? the above is full of comments line and is hard to read...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old October 2nd, 2007, 07:54 AM
Authorized User
 
Join Date: Oct 2005
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i'm sorry about that, i edited again...my problem is that i cant get the value from the textbox inside the datagrid...just get the null value in my database...

when i try to run this query :

 Dim queryString As String = "Insert Into Result (Comment,Mark,StudentA,StudentB,GroupStudentID,Rep ortID)" & _
                   " VALUES('" & com & "', '" & mark & "', '" & "9" & "', '" & "9" & "', '" & "1" & "', '" & "3" & "')"


i didn't get value from these textbox:






Code:
<asp:TextBox ID="sMark" runat="server"></asp:TextBox>
<asp:TextBox ID="sComment" runat="server" Rows="3" Columns="3" ></asp:TextBox>
 
Old October 2nd, 2007, 08:09 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

ok.. I don't know where are you calling this, but you have to think that this control that you are trying to find, are repeated for every row in the grid, so you have to get first the row you need, then find them inside the row..

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old October 2nd, 2007, 08:09 AM
Authorized User
 
Join Date: Oct 2005
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

After users click the submit button, its simple call this method submitReivew()...1st thing that after the datagrid is generated, it already knew how many row they were...and one more thing is that i tried to put it in the loop when the datagrid is generated, when the user click submit button...so it will insert 1 by 1 in database...

thats wat im think but...havent get it right

hix
 
Old October 2nd, 2007, 08:25 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

ok, but you need to go row by row them.. and find the controls inside every row...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old October 2nd, 2007, 08:30 AM
Authorized User
 
Join Date: Oct 2005
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

can you show me how...? still stuck in this hix

 
Old October 2nd, 2007, 08:52 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

in your for...next loop, you need to add something like
datagridvie.Rows.Item(i).FindControl

where i is the number of row...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old October 2nd, 2007, 09:37 AM
Authorized User
 
Join Date: Oct 2005
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hix you know how it come with this error ? just get the value from textbox...

Object reference not set to an instance of an object.

Dim mark As TextBox = Items.Item(1).cell(0).findcontrol("sMark") // error
 
Old October 2nd, 2007, 10:05 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

well.. I don't know what the first items refers too.. but probably you have a problem there...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========




Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Text of Textbox inside Template DarkForce ASP.NET 2.0 Basics 3 September 14th, 2012 07:11 AM
User COntrol Datagrid inside datagrid rodmcleay ASP.NET 1.0 and 1.1 Professional 3 April 14th, 2007 10:11 AM
TextBox inside GridView michurin ASP.NET 2.0 Basics 2 January 13th, 2007 12:51 PM
Use Response object inside asp:textbox tag fizzerchris ASP.NET 1.0 and 1.1 Basics 0 August 22nd, 2006 07:24 PM
dropdownlist inside datagrid shaileshmark General .NET 5 June 27th, 2004 05:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.