Ajax CalendarExtender not displaying 2nd row on - asp.net

I have a Ajax CalendarExtender, ID'd to a textbox and data sourced to more than one record.
If the textbox's are all blank, no assigned value. The textbox's will popup the calendar with click.
If the textbox's contain a value, the first textbox will pop a blank calendar and the rest will pop nothing.
I have stand-alone textbox's with the ajax calendar and they work fine. Here is what I have with assigned value.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns = "false">
<Columns>
<asp:TemplateField HeaderText="Maturity Date">
<ItemTemplate >
<asp:TextBox ID="txtMatureDate" text="4" runat ="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="maturitydate" TargetControlID="txtMatureDate" Format="MMMM,yyyy" runat ="server" DefaultView="Months" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Here is datasource.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim SqlDataSource3 As New SqlDataSource()
SqlDataSource3.ID = "SqlDataSource3"
Me.Page.Controls.Add(SqlDataSource3)
SqlDataSource3.SelectCommand = "select maturitydate from PFW_LPMCalc_test where maturitydate >= '02/01/2017' and maturitydate <= '07/31/2017' order by maturitydate desc"
SqlDataSource3.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("jdwholegoods").ConnectionString
GridView1.DataSource = SqlDataSource3,
GridView1.DataBind()
End Sub
I have scriptmanager in place and

Ok.. so I uninstalled the Ajax Toolkit and reinstalled. It had a newer version though I don't think that did it. My guess is something was on top of current version and it needed to be back on top.

Related

Get row values programmatically from gridview

I have a GridView Control and one button:
<asp:GridView ID="grdView" runat ="server" AutoGenerateColumns ="false" >
<Columns>
<asp:TemplateField HeaderText ="Balance">
<ItemTemplate>
<%#Eval("Balance") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button runat="server" ID ="btn" Text ="test"/>
Then on load page, I populate the gridView with a list of agreements. on that list there are one field called "Balance":
Private Sub form1_Load(sender As Object, e As EventArgs) Handles form1.Load
Dim agreementManager As AgreementManager = New AgreementManager()
Dim lstBalances As List(Of Agreement) = agreementManager.GetByClientId(2)
grdView.DataSource = lstBalances
grdView.DataBind()
End Sub
Then it display me this after loaded:
I am trying to read programmatically one specific balance with:
Private Sub btn_Click(sender As Object, e As EventArgs) Handles btn.Click
Dim value As String = grdView.Rows(1).Cells(0).Text
End Sub
But the "value" is empty.
What I am doing wrong?
I am working on mock a system that uses this way to read the values from a grid view, and this code works fine:
Dim balance As Decimal =
CType(grdApplyTransactionsAgreements.Rows(idx).Cells(BALANCE_CELLID).Text, Decimal)
this code is inside a button too.
Thanks!!
The .Text property can only be read after DataBinding from AutoGenerated columns and BoundField columns. But even if you could I would not recommend it since all you are getting is a string, not the original datatype.
Better read the values from the source lstBalances.
I bumped into an answer, I need to use BondField Control instead Template Field, now everything runs fine.
<asp:GridView ID="grdView" runat ="server" AutoGenerateColumns ="false" >
<Columns>
<asp:BoundField DataField ="Balance" HeaderText ="Balance"/>
</Columns>
</asp:GridView>

In ASP.NET, how do I change the visibility of a button in the same column of a gridview itemtemplate when the other button is clicked?

I have the following gridview:
<asp:GridView ID="gridOpenMECs" runat="server">
<Columns>
<ItemTemplate>
<asp:ImageButton ID="btnShow" runat="server" ImageUrl="xxx.png"
OnClick="btnShow_OnClick" />
<asp:ImageButton ID="btnHidden" runat="server"
ImageUrl="yyy.png" Visible="false" />
</ItemTemplate>
</Columns>
</asp:GridView>
When button1's onclick serverside event is fired I want to obtain a handle on button2 so that I may change its Visible attribute to True.
Protected Sub btnShow_OnClick(ByVal sender As Object, ByVal e As ImageClickEventArgs)
Dim btn as ImageButton = CTYPE(sender, ImageButton) 'get the sending button handle
'' what next to make btnHidden visible?
End Sub
How can I accomplish this? Thank you.
Sorry, C# speak ...
GridViewRow whichrow = (GridViewRow)btn.NamingContainer;
ImageButton btnHidden = (ImageButton)whichrow.FindControl("btnHidden")

Object not set to an instance in asp.net

i have this code:
Dim txt = CType(GridView1.FindControl("cnt_content"), TextBox)
txt.Attributes.Add("style", "word-wrap:break-word;")
i'm always getting that txt is an object not set to an instance of an object
that's my asp code:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False"
DataKeyNames="cnt_id">
<Columns>
<asp:TemplateField HeaderText="Content">
<EditItemTemplate>
<asp:TextBox ID="cnt_content" runat="server" Text='<%# Bind("cnt_content") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblcnt_content" runat="server" Text='<%# Bind("cnt_content") %>'></asp:Label>
</ItemTemplate>
<ItemStyle wrap="true" Width="400px" />
</asp:TemplateField>
any help?
My guess is that you are trying to find this control in the RowDataBound event, like this:
Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
End Sub
You need to only check for this control on data rows, not header or footer rows, as the control will not exist in those other types of rows, try this:
Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
' Only check in data rows, ignore header and footer rows
If e.Row.RowType = DataControlRowType.DataRow Then
' Determine if you are in edit mode or not
If GridView1.EditIndex = -1 Then
' Not in edit mode so look for label control defined in ItemTemplate of grid view
' Put logic here for label control
Else
' In edit mode so look for textbox control defined in EditItemTemplate of grid view
Dim txt = CType(GridView1.FindControl("cnt_content"), TextBox)
txt.Attributes.Add("style", "word-wrap:break-word;")
End If
End If
End Sub
It means that GridView1.FindControl("cnt_content") is returning null, which likely means that GridView does not directly contain a control called "cnt_content".

Passing a values from Datatable to UserControl Property

I am new to programming. I'm creating a program which adds a UserControl to a Gridview template dynamically and I want to pass a value from datatable to a property of a UserControl. The TemplateField in Gridview is already preloaded with 1 user control and if I clicked on a button, this will add a new UserControl with a numbering.
Here is the code from the page on FormLoad event.
Dim dtSESRatings As New DataTable
dtSESRatings.Columns.Add("IncrementNumber")
dtSESRatings.Rows.Add("1")
ViewState("dtSESRatings") = dtSESRatings
gvSesRating.DataSource = dtSESRatings
gvSesRating.DataBind()
And I want to add the row to the Numbering label in the user control which is the IncrementNumber Property set on SESRatings.ascx.
This is the asp code:
<asp:GridView ID="gvSesRating" runat="server" Width="100%" ShowHeader="false" GridLines="None"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<ses:SESRatings runat="server" ID="ses1" IncrementNumber="1" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
After FormLoad, upon clicking on a button "ADD NEW RATING", it is supposed to create a new user control in the gridview and the code is here:
Protected Sub btnAddRating_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAddRating.Click
Dim dt As DataTable = ViewState("dtSESRatings")
Dim dtCnt As Integer = dt.Rows.Count
dtCnt += 1
dt.Rows.Add(dtCnt)
ViewState("dtSESRatings") = dt
gvSesRating.DataSource = dt
gvSesRating.DataBind()
dt = Nothing
End Sub
I want that the user control that will be added in the GridView will get the dtCnt and pass it to the IncrementNumber Property of the User Control. How can I do that? Please help. Thanks.
you must use Eval tags in your gridview control:
<ses:SESRatings runat="server" ID="ses1" IncrementNumber='<%# Eval("IncrementNumber") %>' />

ASP.NET - GridView - How to programmatically add and read new controls to the cell?

Here is the setup:
I programmatically populate my gridview using LINQ to SQL query. Then I enter the edit mode and want to replace some standard TextBox controls with DropDownLists like this:
'excerpt from GridView1_RowEditing
Dim ddlist1 As New DropDownList
Dim res1 = From items1 In mydb.Items
Select items1.Col10
ddlist1.DataSource = res1
ddlist1.DataBind()
GridView1.Rows.Item(0).Cells(1).Controls.Add(ddlist1)
At this moment I have my gridview showing standard textbox control and new DDList control (in the Column 1).
The problem is -- I cant read the value from DDList in the RowUpdating method. It seems like DDList control is not in the GridView1.Rows.Item(0).Cells(1).Controls collection.
RowUpdating method sees only standard TextBox control and can read it's value.
Any suggestions are welcome. I just don't understand something here :(
Use TemplateField, and then you can locate your dropdown using FindControl
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
...
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim ddl = CType(GridView1.Rows(e.RowIndex).Cells(1).FindControl("DropDownList1"), DropDownList)
End Sub

Resources