I have a table in the itemtemplate of a gridview.
My requirement is something like what's shown in the below link
http://img253.imageshack.us/img253/5987/requirement.jpg
i.e. Say 3, 4 and 5 are user id's.
The middle column can contain some information about that user.
Say for User 3 we have Info 1, Info 2 and Info 3 in those three rows.
Similarly, for user 4 and 5, we would have some values in the middle column.
The number of rows in the middle column can vary. It depends on the number of rows
returned by the DB call for that user.
So, how can I achieve this using grid view?
Will it be possible for me to add rows in the databound event dynamically by looking
at the previous or next row in the datasource? If so, how should I go about it?
Or is there an easier/better way to do it?
Thanks
You can take a literal control in the itemtemplate field for the middle column and bind it on rowdatabound event with dynamic created table with the user data.
You might want to maybe think about using a Repeater to generate the outer table and perhaps embed a Gridview into each row to do the detail - I think this might give you a bit more flexibility in your layout.
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<HeaderTemplate>
<table border="1">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="Label1" Text='<%# DataBinder.Eval(Container.DataItem, "UserID") %>' runat="server" />
</td>
<td>
<asp:GridView ID="Gridview1" runat="server" />
</td>
<td>
<asp:Button ID="Button1" Text="Submit" runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Related
I am having a bit of trouble with a dynamic asp.net FormView (within Insert.aspx.vb) in my ASP.NET LINQ to SQL Website. Here is the code for the FormView...
<asp:FormView runat="server" ID="FormView1" DataSourceID="DetailsDataSource" DefaultMode="Insert"
OnItemCommand="FormView1_ItemCommand" OnItemInserted="FormView1_ItemInserted" RenderOuterTable="false">
<InsertItemTemplate>
<table id="detailsTable" class="DDDetailsTable" cellpadding="6">
<asp:DynamicEntity runat="server" Mode="Insert" />
<tr class="td">
<td colspan="2">
<asp:LinkButton runat="server" CommandName="Insert" Text="Insert" />
<asp:LinkButton runat="server" CommandName="Cancel" Text="Cancel" CausesValidation="false" />
</td>
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>
When this form is displayed in a browser, there are 5 user input controls, and two buttons (insert/cancel). But here in the code, I do not see any reference to the 5 user input controls, unless they are represented by this line of code...
<asp:DynamicEntity runat="server" Mode="Insert" />
First, am I correct in assuming that this line of code builds the user input controls dynamically?
And, my actual problem -- I need to set the Focus to the first of these input's upon page initialization. Basically when someone chooses to insert a new item and is sent to this page, I want them to be able to start typing right away, without the need to actually click in that textbox to begin. Any help would be greatly appreciated?
I was able to resolve my issue by adding a Search field via Code, and then using this in the Page_Load event...
If table.DisplayName = "Employees" Then
MultiSearchFieldSet.Visible = True
txbMultiColumnSearch.Focus()
I'm having problem finding information on selecting data from an Entity Framework entity from within the markup of an ASP.Net Repeater
I have a Repeater like this:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="s_Options">
<HeaderTemplate>
<table>
<tr>
<th>Manager Name</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><% !!!!! MY PROBLEM IS HERE %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
And I have an Entity called Option.
Option has 3 members:OID, Option_Type, and Option_Value
I am trying to populate this repeaters with Option_Values where Option_Type = "This Option" but I am completely lost on how to do this in the item template and I am having trouble wording my question correctly to find answers to it elsewhere.
First of all, if doing this in the markup for the Repeater is not the best way, please let me know.
Additionally, I am looking for any help on how to filter this entity and how the markup looks.
Also, if this is something that has been covered somewhere else, then I apologize, I must be asking the question incorrectly. If you could help me articulate what I'm asking in a more constructive way, please let me know.
If I understand you question correctly, you want -
<ItemTemplate>
<td><%# Eval("Option_Type") %></td>
</ItemTemplate>
Take a look at the bottom of Displaying Data with the DataList and Repeater Controls article.
Use this code and put your table column name in Eval..
<table style="width: 400px">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td>
<asp:Label ID="LBLtEXT" runat="server" Text='<%#Eval("Your filed name ")%>'></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
One of pages contains a Repeater control. Earlier, I bind a static number of columns to the repeater. For example, my stored procedure will return Name,Age,Salary,Phone,DOB of an employee. So I could use like the following
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblSalary" runat="server" Text='<%#Eval("Salary")%>' ToolTip="Salary"></asp:Label>
</td>
</tr>
</ItemTemplate>
Now I want to change the design. I have a settings page and I will say which columns should be listed here. Some time I need to list only Name and Age etc. So I can not hard code the design of Repeater. What is the best way to handle the situation ? Is it good to dynamically add labels to the item template?
One approach is to have a user control for each field that may be displayed. Whether the same user controls for all the field that is configurable or a separate control for each field. Then when you bind the repeater you can set the Visible property of the control accordingly.
Is that the direction you wanted to go?
You could use a GridView with TemplateFields. Depending on the settings you show or hide the columns. Here you find a documentation of the TemplateField.
EDIT: Another control with more flexibility than Repeater is the ListView.
If you want to use the Repeater Control you can use placeholders to turn on and off single columns. Just put every column into a PlaceHolder and turn on and off the visibility. Instead of a PlaceHolder you can of course use a UserControl as well.
EDIT 2: Solution with PlaceHolder could look like this:
<ItemTemplate>
<tr>
<asp:PlaceHolder Visible="<%# IsSalaryVisible %>" runat="server">
<td>
<asp:Label ID="lblSalary" runat="server" Text='<%#Eval("Salary")%>' ToolTip="Salary"></asp:Label>
</td>
</asp:PlaceHolder>
<asp:PlaceHolder Visible="<%# IsNameVisible %>" runat="server">
<td>
<asp:Label ID="lblSalary" runat="server" Text='<%#Eval("Name")%>' ToolTip="Salary"></asp:Label>
</td>
</asp:PlaceHolder>
</tr>
</ItemTemplate>
I have a table with the following structure,
I need to restructure the table to show the CustomSpaceName in the following order,
Space3 Personal Case Quick case
Space1 Space2
For each entry I will create a link button and pass the CustomSpaceId in query string.
So which is the ASP.NET Data Control matches best with my requirement. I think using the loop and generate table structure is a BAD idea.
No Need of doing that with a old method when ASP.net gives you GridView and other Data Bounding controls
Basically gridview will do the same operation that you told in a efficient way.
You can use the in-built methods.
Grid View
Repeater
ListView
DataList
Here I will recommend DataList.
Use RepeatColumns="4" property.
<asp:DataList ID="DataList1" RepeatColumns="4" runat="server">
<HeaderTemplate>
<asp:Label runat="server" ID="lbl1" Text='Header'></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label runat="server" ID="lbl1" Text='<% Eval("CustomSpaceName ") %>'></asp:Label>
</ItemTemplate>
</asp:DataList>
I realise there are many posts on the web about this already but I cant seem to find any for my particular problem!
I have a dynamic table that is populated using a repeater.
the code is:
<asp:Repeater ID="rptPending" runat="server">
<HeaderTemplate>
<table id="tblPending" cellpadding="0" cellspacing="0" border="0" class="display">
<thead>
<tr>
<th>Company Name</th>
<th>Telephone</th>
<th>Fax Number</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td runat="server">
<asp:TextBox ID="a" runat="server" TextMode="MultiLine" Rows="1"
onChange="__doPostBack($(this).attr('name'),$(this).parent().attr('id'));"
Text='<%# Eval("_companyName")%>'></asp:TextBox>
</td>
<td runat="server">
<asp:TextBox ID="b" runat="server" TextMode="MultiLine" Rows="1"
onChange="__doPostBack($(this).attr('name'),$(this).parent().attr('id'));"
Text='<%# Eval("_telephone")%>'></asp:TextBox>
</td>
<td runat="server">
<asp:TextBox ID="c" runat="server" TextMode="MultiLine" Rows="1"
onChange="__doPostBack($(this).attr('name'),$(this).parent().attr('id'));"
Text='<%# Eval("_faxNo")%>'></asp:TextBox>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody> </table>
</FooterTemplate>
</asp:Repeater>
Once this table has been populated with data from a datasource, a jquery script iterates through every table cell and edits the id's accordingly. cell_0_0, cell_0_1, cell_0_2 etc.
Now When the text on these text areas change, a postback is initiated, with the __EVENTTARGET being the textarea ID, and the __EVENTARGUMENT being the table cell (parent) ID.
These get sent to the server-side no problem. The issue I am having is GETTING THE TEXT inside the text area...
I have tried adding controls using FindControl("cell_0_0"); Which returns null. Then i found out the FindControl() function IS NOT recursive, so i copied a recursive function off the net... and it Still Fails!
Basically ALL i need to do is GET the value (either innerText or InnerHTML). Ive tried using Control, HtmlControl, HtmlTableRow, and HtmlTextArea.
I just cant seem to get the value. Ive tried recursing throught i a noted earlier, but the controls arent even registered. Im confused.
PLEASE HELP!
Thanks
Alex
Well this is a usually issue, because of the timing of the creations of the controls, and when you create control inside a repeater the timing is even more complex because repeater must first full bind, and then search for the controls.
In my programs to avoid all that I just get the posted value from the Form and I actually not first search to find the control. So just get your posted values from the Request.Form and move on.
Request.Form
All the post data lives on Request.Form, so you can simple get the one you need, or find the one you need. Just a note, to get a value using the Form use the UniqueID, and not the ClientID. Even better get the value from your custom name ids.