Answered by:
select queery inside the griview template textchanged event-VB.NET

Question
-
User-1578974752 posted
Hi
Below code is from a template textbox inside the grid view.
When the id value placed that textbox ,textchanged event will be called.when i debug the value is showing inside descript3 = drd.Item("description").But it is not showing inside the gridview.
Cells(3) is a template textbox .Appreciate the helpProtected Sub partt_TextChanged(sender As Object, e As EventArgs)
Dim box As TextBox = CType(sender, TextBox)Dim hidden As HiddenField = CType(box.NamingContainer.FindControl("HiddenField2"), HiddenField)
Dim descript As String = CType(box.NamingContainer, GridViewRow).Cells(3).Text
Dim count As Int32 = -1
For Each item As GridViewRow In kgrid.Rows
If item.RowType = DataControlRowType.DataRow Then '
count = count + 1
''' If count > CInt(hidden.Value) Or count < CInt(hidden.Value) Then'
Trycmd.Connection = conn
conn.Open()
cmd.CommandText = "select description from items_v where se1 ='" + box.Text + "' AND id=1 "
drd = cmd.ExecuteReader
If drd.HasRows = True Then
drd.Read()
descript = drd.Item("description")
End If
Catch ex As Exception
Finally
cmd.Dispose()drd.Close()
conn.Close()
End TryWednesday, February 27, 2019 3:42 AM
Answers
-
User-1578974752 posted
Instead of descript = drd.Item("description"), I changed to
CType(box.NamingContainer, GridViewRow).Cells(3).Text = drd.Item("description")
now the values are showing. Thanks
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, February 27, 2019 5:11 AM -
User61956409 posted
Hi shsu,
Firstly, glad to hear that you resolve the issue by yourself, and thanks for sharing the code sample.
when i debug the value is showing inside descript3 = drd.Item("description").But it is not showing inside the gridview. Cells(3) is a template textbox. Appreciate the helpIf it is a TextBox control in GridView row Cells(3), you can use FindControl() method to find that TextBox control from cells first, and then assign the description text to it.
<asp:TemplateField HeaderText="des"> <ItemTemplate> <asp:TextBox ID="des" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateField>
CType(CType(box.NamingContainer, GridViewRow).Cells(3).FindControl("des"), TextBox).Text = drd.Item("description")
With Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 28, 2019 2:28 AM
All replies
-
User-1578974752 posted
Instead of descript = drd.Item("description"), I changed to
CType(box.NamingContainer, GridViewRow).Cells(3).Text = drd.Item("description")
now the values are showing. Thanks
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, February 27, 2019 5:11 AM -
User61956409 posted
Hi shsu,
Firstly, glad to hear that you resolve the issue by yourself, and thanks for sharing the code sample.
when i debug the value is showing inside descript3 = drd.Item("description").But it is not showing inside the gridview. Cells(3) is a template textbox. Appreciate the helpIf it is a TextBox control in GridView row Cells(3), you can use FindControl() method to find that TextBox control from cells first, and then assign the description text to it.
<asp:TemplateField HeaderText="des"> <ItemTemplate> <asp:TextBox ID="des" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateField>
CType(CType(box.NamingContainer, GridViewRow).Cells(3).FindControl("des"), TextBox).Text = drd.Item("description")
With Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 28, 2019 2:28 AM