Couldn't get values of textbox from footer row of gridview - asp.net

Actually my problem is i want to insert new row in a footer row of gridview while clicking the button which is outside of the gridview,i couldn't get the values of text box in the footer row of gridview
my coding is
Dim footerRow As GridViewRow = grvTBD_LoanProducts.FooterRow
Dim sStateCode As String = TryCast(footerRow.FindControl("txtStateCode"), TextBox).Text
Dim sEntryTypeID As String = TryCast(footerRow.FindControl("txtEntryTypeID"),TextBox).Text
the above coding didn't works help me to fix it thanks in advance

Try This code it might work:
Protected Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs)
Dim txtName As TextBox = TryCast(GridView1.FooterRow.FindControl("txtStateCode"), TextBox)
Dim aa As String = txtName.Text
End Sub

Related

Add conditional dropdownlist items in ASPX Application (VB)

I have a GridView with a asp:dropdownlist
I am able to add dropdown values using rowdatabound.
However what I need to do, is add specific dropdown list values base on the contents of another cell in that row.
So for example if Row(1) and Cell(2) = MAR001, I want the Dropdown values Four, Five and Six
However if Row(1) and Cell(2) <> MAR001, I want the dropdown values One, Two and Three.
Here is my attempt using a loop, however it doesn't target the dropdown values correctly.
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
For i As Integer = 0 To GridView1.Rows.Count - 1
Dim Name As String = GridView1.Rows(i).Cells(2).Text
If Name = "MAR001" Then
Dim ddl As DropDownList = e.Row.FindControl("ddlQuantity")
Dim numbers As New List(Of String)()
numbers.Add("Four")
numbers.Add("Five ")
numbers.Add("Six")
ddl.DataSource = numbers
ddl.DataBind()
Else
Dim ddl As DropDownList = e.Row.FindControl("ddlQuantity")
Dim numbers As New List(Of String)()
numbers.Add("One")
numbers.Add("Two")
numbers.Add("Three")
ddl.DataSource = numbers
ddl.DataBind()
End If
Next
Else
End If
End Sub
Any help much appreciated.
Not sure if this is what you need, but try finding the textbox first and get the text value of that.
Edit: i just realized you're looping the rows. you don't have to do that - this is the RowDataBound event, so this code happens for every row.
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ddl As DropDownList = e.Row.FindControl("ddlQuantity")
Dim numbers As New List(Of String)()
Dim customerid As String = (e.Row.Cells(2).Text)
If customerid = "MAR001" Then
numbers.Add("Four")
numbers.Add("Five ")
numbers.Add("Six")
Else
numbers.Add("One")
numbers.Add("Two")
numbers.Add("Three")
End If
ddl.DataSource = numbers
ddl.DataBind()
End If

Access Individual Row Template in GridView

I have a ListBox (named ListBoxProperty) and button (btnDeselectAll) in a TemplateField on a gridview control that shows on every row of the gridview. The code shown below is the code behind the button control in the TemplateField. This code works on every ListBox on every row in the gridview. I would like it to only affect the ListBox in the gridview row from which it was clicked. I've tried a few things with failure so I didn't include my failings - just the portion that almost gives me what I want. Couldn't include a pic alas my reputation is weak.
Protected Sub btnDeselectAll_Click(sender As Object, e As System.EventArgs)
For Each Row As GridViewRow In GridView1.Rows
Dim myListBox As ListBox = _
CType(Row.FindControl("ListBoxProperty"), ListBox)
For Each selectedItem As ListItem In myListBox.Items
selectedItem.Selected = False
Next
Next
End Sub
The NamingContainer of the button is the GridViewRow, there you are.
Protected Sub btnDeselectAll_Click(sender As Object, e As System.EventArgs)
Dim btn = DirectCast(sender, Button)
Dim row = DirectCast(btn.NamingContainer, GridViewRow)
Dim myListBox = DirectCast(row.FindControl("ListBoxProperty"), ListBox)
For Each selectedItem As ListItem In myListBox.Items
selectedItem.Selected = False
Next
End Sub

trying get total from grid view textbox

i want to get value from grid view text box in Text Change Event but error comes
Object refrence is not set of an instance of an Object
Protected Sub onDebitChange(ByVal sender As Object, ByVal e As EventArgs)
Dim a, b As Integer
With GridView3
Dim rows As Integer = .Rows.Count
For i As Integer = 0 To rows - 1
Dim txtDebit As TextBox = CType(GridView3.Rows(i).FindControl("TotalDebit"), TextBox)
a = Val(txtDebit.Text)
b += a
Next
DebitBalance.Text = b
End With
End Sub
i also had tried for each loop but error is same
please help
You need to put the name of the ItemTemplate control correctly, in onDebitChange method please fix the control name to "Debit" not "TotalDebit" only:
Dim txtDebit As TextBox = CType(GridView3.Rows(i).FindControl("Debit"), TextBox)
Hope this helps.

asp.net Editable GridView - set Header text color

In the asp.net editable gridview I have header text as 'FieldName *'.
As I am allowing user to enter the data and the data is mandatory.
Can I set FieldName with blue color and * with red color in header ??
If yes..how?
You can insert HTML code into the HeaderText for the FieldName.
Like this
HeaderText="<font color="blue">FieldName </font><font color="red">*</font>"
The page will interpret the HTML code and show it as you desire.
But you may have to set the HtmlEncode property for your BoundField in order to force the page to interpret the HTML code.
You can make something out of this code.
Protected Sub gvName_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvIndexing.RowCreated
If e.Row.RowType = DataControlRowType.Header Then
Dim oGridView As GridView = CType(sender, GridView)
Dim oGridViewRow As GridViewRow = New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert)
Dim oTableCell As TableCell = New TableCell()
oTableCell.Text = "Header Value"
oTableCell.CssClass = "GridViewHeaderCSSClass"
oTableCell.ColumnSpan = 2
oGridViewRow.Cells.Add(oTableCell)
oGridView.Controls(0).Controls.AddAt(0, oGridViewRow)
Else
Dim oGridView As GridView = CType(sender, GridView)
oGridView.ShowHeader = False
End If
End Sub

use gridview row control in sqldatasource insert command

I am trying to use a label from another row in the gridview and insert it in a table when the user clicks the button which is in its own column.
my problem is that i cant get bookno which finds the label set to the #bookno in my sqldatasource
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim selectedRow As Button = DirectCast(sender, Button)
Dim bookno As Label = CType(selectedRow.FindControl("label1"), Label)
Dim why As TextBox = CType(selectedRow.FindControl("textbox2"), TextBox)
Dim yesint As Integer = 1
Dim sql As SqlDataSource = CType(selectedRow.FindControl("sqldatasource4"), SqlDataSource)
sql.InsertParameters.Add(bookno.Text, 0)
sql.Insert()
End Sub
Try
Dim bookno As Label = CType(selectedRow.Parent.FindControl("label1"), Label)
and see if you get a valid control for bookno. If it works, do the same for other FindControl() calls.

Resources