What i'm trying to do : I have some meeting date in my database. For display this, I want make one GridView for each day. (I have several meetings by days). And after, put this gridview in accordionPane (one by day). I want put in Pane for not display a long list in the screen.
I know how make dynamics accordionPanes, I know make dynamics GridView (depends on the number of meetings).
I know put one GridView in one accordionPane. (juste for statics one)
But I can't put dynamically GridViews in accordionPanes...
The source code of my problem :
The way to create dynamic number of accordionPanes :
Code Behind :
For i = 1 To j
Dim volet As New AjaxControlToolkit.AccordionPane
volet.Visible = True
volet.ID = "volet" & i.ToString
Accordion1.Panes.Add(volet)
Next
Code ASP.NET :
<asp:Accordion ID="Accordion1" runat="server" Width="873px" CssClass="accordion" FadeTransitions="true" HeaderCssClass="accordionHeader" HeaderSelectedCssClass="accordionHeaderSelected" RequireOpenedPane="false" ContentCssClass="accordionContent" TransitionDuration="100">
</asp:Accordion>
The way to create dynamic number of GridView :
Code behind :
For i = 1 To j
Dim datag As New GridView
datag.Visible = True
datag.ID = "datag" & i.ToString
Panel1.Controls.Add(datag)
Next
Now I try to insert GridView in accordionPanes. That's my issue.
I hope i'm clear, ask me if i'm not well expressed.
Thanks a lot for your answers
I found my answer !
I missed two functions : pane.ContentContainer.Constrols.Add and pane.HeaderContent.Controls.Add.
For i = 1 To j
Dim datag As New GridView
Dim title As New Label
datag = GenererGridView(i) 'GridView from database
datag.Visible = True
datag.ID = "datag" & i.ToString
title.Text = "datag" & i.ToString
Dim pane As New AjaxControlToolkit.AccordionPane
pane.Visible = True
pane.ID = "pane" & i.ToString
pane.ContentContainer.Controls.Add(datag)
pane.HeaderContainer.Controls.Add(title)
Accordion1.Panes.Add(pane)
Next
Related
I am getting started with a basic asp.net gridview control and I just dont seem to be able to make it visible in the web browser at all in an asp.net web application.
Here is what I have just to get myself started off. In the aspx page ...
<asp:GridView ID="myGr" runat="server" BackColor="Aqua" AutoGenerateColumns="True" Width="100%" ViewStateMode="Enabled"></asp:GridView>
In the code behind I have ...
Dim tbl As New DataTable
tbl.Columns.Add("ID", GetType(Int32))
tbl.Columns.Add("Name", GetType(String))
tbl.Columns.Add("Birthday", GetType(Date))
Dim pers As DataRow = tbl.NewRow
pers("ID") = 1
pers("Name") = "Tim"
pers("Birthday") = New Date(1973, 6, 9)
myGr.DataSource = tbl
myGr.DataBind()
Would be great if anyone could give me some basic advice on this control
You need to add the row you inserted to the datatable tbl. Because you haven't done this, the datatable is empty so the Gridview is empty too.
Like that: tbl.Rows.add(pers)
You create row but you do not add it to the table.
You have to add line like that:
tbl.Rows.Add(pers)
I've been struggling on a way to do this for a while. I have this a listbox in asp.net that I use that looks like :
<asp:ListBox ID="lstLinkedProspect" runat="server" SelectionMode="Multiple" />
What I want to do with it is to be able to select all items I have in a specific table, all except the one that are in the listbox. Not only the selected but all items that are already in the list. I use System.Linq.Dynamic library. Here is what I'm trying to do :
Dim lstProspect = dbConnection.Prospects.Where(If(String.IsNullOrWhiteSpace(SearchFilters.Value), "ProspectId > 0", SearchFilters.Value).ToString) _
.Except(' There goes all the items in the list box)
What I have already tried is :
Dim lstProspect = dbConnection.Prospects.Where(If(String.IsNullOrWhiteSpace(SearchFilters.Value), "ProspectId > 0", SearchFilters.Value).ToString) _
.Except(lstLinkedProspect.Items.Cast(Of ListItem)().Where(Function(x) x.Value).Cast(Of Beans.Prospect))
Is it possible in Linq to get all the items from a table that are not in the listbox? Note that the Value property of the ListItem in the listbox is the ProspectId.
Thanks in advance.
This is the the code I found to achieve what I was looking for :
Dim lstItems = dbConnection.Prospects.Where(Function(x) ids.Contains(x.ProspectId))
Dim lstProspect = dbConnection.Prospects.Where(If(String.IsNullOrWhiteSpace(SearchFilters.Value),
"ProspectId > 0", SearchFilters.Value).ToString).Except(lstItems)
Hope this can help anyone struggling with that problem.
I have a GridView which is programatically filled from the DB (not a SqlDataSource or such). There are 4 columns which are TemplateFields as I format their text. They are Dates and Times and this is the one of their TemplateField:
<ItemTemplate>
<asp:Label ID="Label1" Text='<%# FormatDate(Eval("tDate")) %>' runat="server"></asp:Label>
</ItemTemplate>
This is the function to format that date:
Function FormatDate(objTime As Object) As String
Dim d As String
If objTime.Equals(DBNull.Value) Then
d = ""
Else
d = Convert.ToDateTime(objTime).ToString("MM-dd-yyyy")
End If
Return d
End Function
I've been using the method in this Post which was converted to VB code from this to convert the GridView to a PDF using iTextSharp.
My issue is that I'm getting a Null Reference exception here when adding the GridView data to the PDF(inside the For Loops):
Dim lc As DataBoundLiteralControl = TryCast(gvReport.Rows(rowNo).Cells(colNo).Controls(0), DataBoundLiteralControl)
s = lc.Text.Trim()
And if I remove this If statement and just run the Else part here:
s = gvReport.Rows(rowNo).Cells(colNo).Text.Trim()
ph = New Phrase(s, FontFactory.GetFont("Arial", ReportTextSize, iTextSharp.text.Font.NORMAL))
mainTable.AddCell(ph)
These Date/Time columns show up as empty on the PDF while all other columns show up with no issues.
I'm very lost on how to resolve this issue and have been unsuccessful in finding a solution online.
While I wasn't able to fix the solution I was following up above, I found a different way to access data from a TemplateField:
Dim s As String = CType(gvReport.Rows(rowNo).FindControl("Label1"), Label).Text
This gives me access to the data in the specified column. Now I just need to figure out a way iterate through the row and get each of the different TemplateFields which will probably involve reworking my For loops and a Select Case statement.
You are getting Nothing because TryCast will store Nothing if it cannot cast the value.
In bound columns, the control is 0, but in an edit item template like that, it is 1.
So you have to change
Dim lc As DataBoundLiteralControl = TryCast(gvReport.Rows(rowNo).Cells(colNo).Controls(0), DataBoundLiteralControl)
to
Dim lc As Label = TryCast(gvReport.Rows(rowNo).Cells(colNo).Controls(1), Label)
I'm using a CheckBoxList to define which columns are displayed in a GridView. I populate the CheckBoxList using a query like
select column_name, data_type from information_schema.columns
where table_name = 'myTable'
After the user has chosen the columns (with various Data Types in them) they wish to display, they press a button and the following snippet of VB code generates the GridView.
For Each item As ListItem In chooseColsList.Items
If item.Selected Then
Dim bf As New BoundField()
'PRODUCES BUGGY RESULTS BECAUSE APPLIED TO ALL BoundFields
bf.DataFormatString = "{0:dd-MMM-yyyy}"
bf.ApplyFormatInEditMode = True
bf.DataField = item.Value
bf.HeaderText = item.Value
bf.SortExpression = item.Value
statusReportGrid.Columns.Add(bf)
End If
Next
What I want to do is to apply the DataFormatString ONLY to the columns with a 'date' Data Type in them. However, I have found no way of programmatically determining the Type of the data in the column being bound, no any way of passing this info to the Control. This information exists in the information_schema, as shown in my query, but I don't know how to extract that out and use it to dynamically setup my BoundFields. It is important to note that I'm using an SqlDataSource.
I've experimented with just about every possible solution I can think of and end up here.
Thanks in advance for your help, it is VERY appreciated :)
If you set your check box list like this:
<asp:checkboxlist id="list" runat="server"
DataTextField="column_name" DataValueField="data_type" DataSourceID="YourDSID" />
You should be able to iterate through the items and check the value of the current Item like so:
For Each item As ListItem In chooseColsList.Items
If item.Selected Then
Dim bf As New BoundField()
If StrComp(item.Value,"date") = 0 Then 'Or however datetime is returned
bf.DataFormatString = "{0:dd-MMM-yyyy}"
bf.ApplyFormatInEditMode = True
End If
bf.DataField = item.Text
bf.HeaderText = item.Text
bf.SortExpression = item.Text
statusReportGrid.Columns.Add(bf)
End If
Next
I have an ASP project which references a WCF service. Does exactly half of what I need.
A button on the page calls a function from the WCF, which returns a list of objects (variable names). When returned, the vb code dynamically adds textboxes to a panel on the page. Like this:
For Each LetterVariables In LetterVarList
tb = New TextBox
lb = New Label
lb.Text = LetterVariables._key & " "
tb.ID = LetterVariables._key
pnlVars.Controls.Add(lb)
pnlVars.Controls.Add(tb)
Dim LineBreak As LiteralControl = New LiteralControl("<br />")
pnlVars.Controls.Add(LineBreak)
Next
Now the problem is, after this is finished the user will enter some values into those texboxes. I (somehow) need to reference those texboxes to snag the values when a user clicks another button.
How can I do this?
Thanks,
Jason
You can give the TextBox an ID which you could use FindControl to retrieve.
tb.ID = "txt" + LetterVariables._key.ToString();
Then when you want to reference it.
TextBox txtBox = (TextBox)FindControl("txt" + someKey);
Something like that might work for you.
Don't forget to recreate the controls on post back BEFORE the controls are loaded with the posted values.