I have a vendor application which is precompiled. I want to add a template column into the aspx page, however I'm having some difficulty.
This works for me fine as "Available" is a column bound to the asp DataGrid:
<asp:TemplateColumn HeaderText="test">
<ItemTemplate>
<asp:Label ID="Label2" Text='<% #DataBinder.Eval(Container.DataItem, "Available") %>' runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
Now, I'm trying to basically create a template column, that takes the (int) "Available" column and divide it by 12 and then multiply by DateTime.Now.Date.Month.
I'm not having any luck with using DateTime within <% %> on this page.
Thanks,
Mark
You can remove inherits="Archive, App_Web_XXXXX" from <%# Page %> then bring your code into ASPX file and modify it.
Related
I have 2 WebServer Controls
<asp:TextBox ID="txtTextBox" runat="server"ClientIDMode="Static"MaxtLength="30"Width="35px"CssClass="labeltext"></asp:TextBox>
<asp:DropDownList ID ="ddlDropDown" runat ="server" CssClass="text">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="U">someValue1</asp:ListItem>
<asp:ListItem Value="Y">someValue2</asp:ListItem>
<asp:ListItem Value="N">someValue3</asp:ListItem>
</asp:DropDownList>
There are no Errors on my aspx Page. I have configured my datasets to read the 2 new columns ( I even double checked the designer file for the dsd and see both new columns). I have cleaned and rebuilt my solution but my code behind (.vb) only see the dropdown and not the Text Box,
So it turns out, somehow the dataset got out of sync. I think it was because I tried to copy and paste a property in my aspx. I undid all my changes and re applied them again with no issue.
I have a grid which gets populate with data from my database. As part of my grid I have a view button which views the records in a modal form.
One of my records has a date. When the textbox in the modal form gets populated with the date it gets displayed like this: "2018/01/25 12:00:00 AM"
I want only the date to be displayed without the time. I have made sure that inside my SQL table that it is only date being saved and it is.
This is the column in my grid:
<asp:BoundField DataField="Date" HeaderText="Date" DataFormatString="{0:dd/MMM/yyyy}" SortExpression="Date"/>
This is my textbox:
<asp:TextBox ID="txtDate" runat="server" placeholder="Date" class="form-control"></asp:TextBox>
I have tried the following but it does not work:
txtDate.Text = Y.Date.ToShortDateString();
Text='<%#((DateTime)Bind("NewDate")).ToString("dd/MM/yyyy")%>'
Text='<%# Bind("JoinDate", "{0:MM-dd-yyyy}") %>'
I tried writing javascript code and limit the characters but the time still shows on load.
I would like only the date to be shown in my textbox.
Please advise. Thanks
change your grid code to this:
<asp:BoundField DataField="Date" HeaderText="Date" DataFormatString="{0:dd/MM/yyyy}" SortExpression="Date"/>
There are three Ms in date format, just remove one M, the format will be {0:dd/MM/yyyy}
I had to convert my date to a specific format in SQL.
I added this to my stored procedure in my select statement
CONVERT(VARCHAR(10), tb_Schedule.Date, 103) [Date]
This should work.
<asp:TextBox Text='<%#DataBinder.Eval(Container.DataItem,"Date", "{0:MM/dd/yyyy}")%>' ID="txtDate" runat="server" placeholder="Date" class="form-control"></asp:TextBox>
If you wish to directly bind your data, then add to the TextBox:
Text='<%# String.Format("{0:MM-dd-yyyy}", Eval("JoinDate")) %>'
I assume you wish to have two-way communication if you are using textbox, so use Eval instead of Bind.
Guys please bear with me here, I've started using this blog to learn visual basics, I seriously want to learn and so far it been helping me a lot. Thank You everyone...
Now my question goes like this:.
Saying I have data in the SQL Server 2005 database and I want to retrieve data from the SQL table and display it on the textbox or listbox. I want to select Faculty_ID,Faculty_Name,F_Description from Faculty table and display these data on the textbox or listbox. And let's say I have my connection working just fine, I just need a statement to retrieve data from SQL table and display it on the textbox.
How do I do that? Please bear in mind you're helping the most stupiest, dumbest guy ever.
Thank You in Advanced!!!!!.
Repeaters are usually used to display data. Below is an example of a repeater. On the back end you can bind it to a list. I'd suggest making your own data structure and then binding it to that. By binding I mean, repeaterID.Datasource = yourDataObject and then repeaterID.Databind
<asp:Repeater ID="fieldList" runat="server">
<HeaderTemplate>
<table border="1" width="75%">
<tr>
<th>
<b>Object Field 1</b>
</th>
<th>
<b>Object Field 2</b>
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr id='<%#Eval("") %>'>
<td>
<asp:Label ID="obj1" runat="server" Text='<%# Eval("SQLObjectFieldRelName1") %>'></asp:Label>
</td>
<td>
<asp:Label ID="obj2" runat="server" Text='<%# Eval("SQLObjectFieldRelName2") %>'></asp:Label>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Text boxes and list boxes going to be less commonly used for any dataset. You'd only really use them for a string or some text. If that's what you want to do then I'd manufacturer your string in your code behind and set your textbox text to it.
I can filter my Gridview with a text box however when I click on a column to sort it the filter is lost. I am assuming that I need to add something into my SQL to handle this.
The below is the SQLdataSource for the DataGrid which links to it. What I need to then add in is a variable datafield and keep the search value.
I can get a search value with a session when I do a search but unsure what I need to do to make the other part work.
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:mySQLConnectionString %>"
DeleteCommand='DELETE FROM [xxx] WHERE ID = #ID'
ProviderName="<%$ ConnectionStrings:mySQLConnectionString.ProviderName %>"
SelectCommand='spFilterSearchModule'
SelectCommandType='StoredProcedure'
>
</asp:SqlDataSource>
I am therefor looking to get two parts of information
1) What do need to do to filter when you click on a column on the datagrid
2) Where do I put it i.e. page Load etc..
You need to add:
FilterExpression="filterfield='expression'"
relpace filterfield with the field you want to filter and change expression to what you want to filter from the field
I am assigning a 'ds' dataset to datagrid.In addition to that I want to add new column with check boxes.That new column will be first column of datagrid.
Currently I am using below code,
DataGrid1.DataSource = dsResult.Tables("Result")
Result table has 4 column....in addtion to that i want to column "Selection" with check boxes
You can add a checkbox inside the itemtemplate like
<ItemTemplate>
<asp:CheckBox ID="chkComplete" runat="server" />
</ItemTemplate>
For a basic understanding read this article
Including a CheckBox Control Inside an ASP.NET DataGrid...