I need to put a table in the div which contains textboxs and labels when someone click on a button.
Structure of table is as below...
<table>
<tr>
<td>
<label id="l1" text="adfa"></label>
</td>
<td>
<input type="text" id="t1">
</td>
</tr>
<table>
The no of rows can vary but the structure of a row will be same as here in the above table.
I am trying to use Placeholder but confused how to put all the stuff their...
Are you performing this operation client-side or server-side (for the latter, are you posting back to the server to update the response)? If the latter, using a ListView control would work perfectly, as you can define it as:
<asp:ListVIew .. ItemPlaceholderID="Items">
<LayoutTemplate>
<table>
<tr runat="server" id="Items" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<label id="l1" text="afda"></label>
</td>
<td>
<input type="text" id="t1">
</td>
</tr>
</ItemTemplate>
</asp:ListView>
Then you can do:
ListView1.DataSource = //some data source
ListView1.DataBind()
The data can be empty rows just to populate the list initially, or some valid data. Some further references:
http://weblogs.asp.net/scottgu/archive/2007/08/10/the-asp-listview-control-part-1-building-a-product-listing-page-with-clean-css-ui.aspx
http://msdn.microsoft.com/en-us/library/bb398790(v=vs.100).aspx
for (int i = 0; i < noofsubject; i++)
{
table.Width = 760;
TableRow tRow1 = new TableRow();
TableCell tCell11 = new TableCell();
tCell11.Text = "Subject " + i;
tRow1.Cells.Add(tCell11);
table.Rows.Add(tRow1);
}
PlaceHolder1.Controls.Add(table);
I was looking for this..
Related
I have this and I want to hide rows dynamically using vb.net codebehind.
I am using VS2010.
This is my table:
<table>
<tr id="FromDateRow">
<td><asp:Label ID="FromDateLabel" runat="server">From date:</asp:Label></td>
<td>
<input type="text" id="txtFromDateF" class="needs-datepicker" />
<asp:TextBox id="txtFromDate" CssClass="hidden" runat="server" />
</td>
</tr>
<tr id="ToDateRow">
<td><asp:Label ID="ToDateLabel" runat="server">To date:</asp:Label></td>
<td>
<input type="text" id="txtToDateF" class="needs-datepicker" />
<asp:TextBox id="txtToDate" CssClass="hidden" runat="server" />
</td>
</tr>
<tr>
<td><asp:Label ID="CustomerCodeLabel" runat="server">Customer Code</asp:Label>:</td>
<td><asp:DropDownList ID="CustomerCodeDropDownList" runat="server" AutoPostBack="False" /></td>
</tr>
<tr>
<td><asp:Label ID="CINumberLabel" runat="server">CI Number</asp:Label>:</td>
<td><asp:TextBox ID="CINumberTextBox" runat="server" /></td>
</tr>
</table>
Now I want to do something like this:
Select Case value
Case DisplayDates.FromDate
ToDateRow.CssClass = "hidden"
FromDateRow.CssClass = ""
Case DisplayDates.ToAndFromDate
ToDateRow.CssClass = ""
FromDateRow.CssClass = ""
Case Else
ToDateRow.CssClass = "hidden"
FromDateRow.CssClass = "hidden"
End Select
For some reason I cannot access the ToDateRow and the FromDateRow from my codebehind.
The objects you are trying to reference in codebehind (the relevant tr elements) needs to be defined as runat="server"
If CssClass is not a known property for the object instance try using the following:
rowObject.Attributes.Add("class", "hidden");
You must have
runat="server
tag in table and tr to access from code behind.
After comment :
ToDateRow.Attributes("class") = "CssClass";
Ok I solved it.
By adding the runat="server" i was able to access the row.
And then I found the "visible"-property.
Now it works just fine.
Thx for the help
I am new to the ASP.NET i am binding one list of data object to the grid view. I want to display blank row after each record in grid view so i have done this by as below in code behind
List<DatabaseDTO> lstdatabase= new List<DatabaseDTO>();
foreach(int jobNumber in JobnumberList)
{
DatabaseDTO dataObject = new DatabaseDTO();
dataobject = GetDatabaseData(jobNumber);//Method to retrieve data and return data object
lstdatabase.Add(dataObject);
lstdatabase.Add(new DatabaseDTO());
}
gridView.DataSource = lstdatabase;
gridView.DataBind();
it's working correct i am getting the desired blank row in the grid view but i know this is not right way because i am adding object to the list so i can add the blank row in place of that i would very much like to adjust this blank row from the aspx page. I know there is another way using the DataTable but it is also not very good because it also adds the unnecessary records to the DataTable. So any other work around or way to solve this would be very great. Thank you.
Try This
<div>
<asp:DataList ID="DataList1" runat="server">
<ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
<HeaderTemplate>
<table width="900px">
<tr>
<td width="300px">
<b>Name</b>
</td>
<td width="300px">
<b>Account No</b>
</td>
<td width="300px">
<b>Company</b>
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table width="900px">
<tr>
<td align="left" width="300px">
<%# DataBinder.Eval(Container.DataItem, "Name")%>
</td>
<td align="left" width="300px">
<%# DataBinder.Eval(Container.DataItem, "AccountNo")%>
</td>
<td align="left" width="300px">
<%# DataBinder.Eval(Container.DataItem, "Company")%>
</td>
</tr>
<tr>
<td align="left" width="300px">
<br />
</td>
<td align="left" width="300px">
<br />
</td>
<td align="left" width="300px">
<br />
</td>
</tr>
</table>
</ItemTemplate>
<HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle>
<SeparatorTemplate><br /></SeparatorTemplate>
</asp:DataList>
</div>
You can't have an empty row in the Datagrid if it isn't present in the data source. You have to think that after all the grid data is just a representation of your data source, if there is a empty row, the grid will show it, if there is not, it wont.
Write a stored procedure to get Output Parameter from sql server and bind to grid view if record is not there..
I have a repeater. And i want to hide and display a particular column for a particular condition. I have three types of subjects and their ids are 0,1,2 respectively. Now i want to show that particular column when the subject will be 2 only..
My code is :-
<table id="table1" class="yui" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th>
EmpID #
</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<asp:Repeater ID="Repaddressorbbl" runat="server" OnItemCommand="Repaddressorbbl_ItemCommand">
<ItemTemplate>
<tr id="gh" style="cursor: pointer" onclick="Select(this);">
<td style="text-align: center;">
<%#Eval("empid")%>
</td>
<td>
<asp:LinkButton ID="lknumber" runat="server" Text="Edit" CommandName="subjectid" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
<tfoot>
</tfoot>
</table>
You could catch the OnItemDataBound event of the repeater and hide the column there if the (subject) item id is 2.
In order you can get a reference to the column, make it a server control:
<td style="text-align: center;" id="COL_TO_HIDE" runat="server"><%#Eval("empid")%></td>
Then in the repeater event you can simply look for the control and hide it:
protected void YourRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
var subject = (Subject)e.Item.DataItem;
if (subject.Id == 2)
{
var col = e.Item.FindControl("COL_TO_HIDE");
col.Visible = false;
}
}
}
Please note, this is just a simplified example which should you get started.
I think you should start by using <HeaderTemplate></HeaderTemplate> and <FooterTemplate></FooterTemplate> to define the start and end of your table just to tidy it up.
You can get the table to run on the server by adding a runat="server" and give the column <td> an id and a runat="server" attribute so you can program server code against it. I'd then eval bind the visible attribute of the cell based on your field value or use attributes.add("display:none") or just use a grid view as suggested in the link.
<asp:Repeater ID="Repaddressorbbl" runat="server"
OnItemCommand="Repaddressorbbl_ItemCommand">
<ItemTemplate>
<tr id="gh" style="cursor: pointer" onclick="Select(this);">
<td style="text-align: center;">
<%#Eval("empid")%>
</td>
<% if (false){ %>
<td>
<asp:LinkButton ID="lknumber" runat="server"
Text="Edit" CommandName="subjectid" />
</td>
<% } %>
</tr>
</ItemTemplate>
</asp:Repeater>
I was wondering if any one could help me out; I have a table which looks something like the following:
<table id="Table1" border="0">
<tr>
<td><b>1.</b> Question 1</td>
</tr><tr>
<td style="border-width:5px;border-style:solid;"></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio1" type="radio" name="Group1" value="Radio1" /><label for="Radio1">Answer1</label></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio1" type="radio" name="Group1" value="Radio1" /><label for="Radio1">Answer2</label></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio1" type="radio" name="Group1" value="Radio1" /><label for="Radio1">Answer3</label></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio1" type="radio" name="Group1" value="Radio1" /><label for="Radio1">Answer4</label></td>
</tr><tr>
<td style="height:30px;"></td>
</tr><tr>
<td><b>2.</b> Question 2</td>
</tr><tr>
<td style="border-width:5px;border-style:solid;"></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio2" type="radio" name="Group2" value="Radio2" /><label for="Radio2">yes</label></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio2" type="radio" name="Group2" value="Radio2" /><label for="Radio2">no</label></td>
</tr><tr>
<td style="height:30px;"></td>
</tr>
</table>
How do I go about looping through each group of radio buttons and getting the text of the selected radio button?
The code displayed above is created dynamically ... in my aspx file I have the following code:
<asp:Table ID="Table1" runat="server">
</asp:Table>
If you want to access the rows in ASP.NET (on the server side), you need to convert the table, rows and the cells to server control (using runat="server") and iterate through the controls in the table.
EDIT : :- If you are adding the rows, cells and radionbuttons following way, all of them will be the server controls (and are runat=server) so that you can access them the way I mentioned above:--
// Create new row and add it to the table.
TableRow tRow = new TableRow();
table1.Rows.Add(tRow);
for (cellCtr = 1; cellCtr <= cellCnt; cellCtr++)
{
// Create a new cell and add it to the row.
TableCell tCell = new TableCell();
RadioButton rdb = new RadioButton();
rdb.ID = "rdb_" + cellCtr.ToString();
rdb.Text = "radio button";
rdb.GroupName = "rdbGroup";
tCell.Controls.Add(rdb);
tRow.Cells.Add(tCell);
}
EDIT:-
You can find the controls in each cell.Something like below:-
foreach(TableCell cell in tableRow.Cells)
{
foreach(Control ctrl in cell.Controls)
{
if(ctrl is RadioButton)
{
if(ctrl.Selected)
{
string rdValue=ctrl.Text;
}
}
}
}
Or If you want to iterate on the client side using Javascript, have a look here and you dont have to apply runat="server".
It sounds like you're starting with a barebones <table> in your markup page, and dynamically adding those <input> afterwards.
Consider taking this approach:
Add the runat="server" attribute to your table.
In the code where you're adding those <input> tags, add a new RadioButton control. Use an ID here that you can predict later. Perhaps you can use a RadioButtonList instead, if the choices are logically grouped!
It's unclear if you're manually adding those <tr> and <td> as strings. Consider the option of new TableRow() and new TableCell(). Then add the new RadioButton to the TableCell.Controls collection with tc.Controls.Add(myNewRadioButton);
In your postback code, simply refer to your RadioButton controls by id, or even loop through the Controls collection property of the Table1.
foreach (Control x in Table1.Controls)
{
if (x.GetType().ToString().Equals("System.Web.UI.WebControls.RadioButton"))
{
if (((RadioButton)x).Checked)
{
//proceed.
}
}
}
Convert all controls to server controls (by adding the runat="server" attribute). You can then programatically access what you need o. The server.
I am currently having an issue with radio buttons and grouping. I have an asp radio button within a repeater control. I have the group name attribute set to "Customer". When the page loads, the radio buttons are not grouped. Instead of the id fields being set to the group name, it is setting the value fields of the radio buttons. I know that I have tried setting radio buttons up outside of a repeater control and have had the same issue. What is going on here?
aspx
<asp:Repeater ID="repCustomers" runat="server">
<HeaderTemplate>
<table class="tableDefault" cellpadding="0" cellspacing="0" border="0" style="width: 383px; border: 0px !important">
<tr>
<th> </th>
<th>Cust. No.</th>
<th>Cust. Name</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:RadioButton ID="radCustomer" GroupName="Customer" runat="server" ValidationGroup="Customer" ToolTip='<%#Eval("CustomerNumber") %>' />
</td>
<td><%#Eval("CustomerNumber")%></td>
<td><%#Eval("Name") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
output html
<table class="tableDefault" cellpadding="0" cellspacing="0" border="0" style="width: 383px; border: 0px !important">
<tr>
<th> </th>
<th>Cust. No.</th>
<th>Cust. Name</th>
</tr>
<tr>
<td>
<span title="111111"><input id="ctl00_PrimaryContent_repCustomers_ctl01_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl01$Customer" value="radCustomer" /></span>
</td>
<td>111111</td>
<td>Jeremy's Test</td>
</tr>
<tr>
<td>
<span title="222222"><input id="ctl00_PrimaryContent_repCustomers_ctl02_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl02$Customer" value="radCustomer" /></span>
</td>
<td>222222</td>
<td>My Test</td>
</tr>
<tr>
<td>
<span title="333333"><input id="ctl00_PrimaryContent_repCustomers_ctl03_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl03$Customer" value="radCustomer" /></span>
</td>
<td>333333</td>
<td>Jim Bob's BBQ</td>
</tr>
<tr>
<td>
<span title="444444"><input id="ctl00_PrimaryContent_repCustomers_ctl04_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl04$Customer" value="radCustomer" /></span>
</td>
<td>444444</td>
<td>New Hope Hamburgers</td>
</tr>
<tr>
<td>
<span title="555555"><input id="ctl00_PrimaryContent_repCustomers_ctl05_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl05$Customer" value="radCustomer" /></span>
</td>
<td>555555</td>
<td>Pied Piper Pizza</td>
</tr>
<tr>
<td>
<span title="666666"><input id="ctl00_PrimaryContent_repCustomers_ctl06_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl06$Customer" value="radCustomer" /></span>
</td>
<td>666666</td>
<td>Sandy's Subs</td>
</tr>
<tr>
<td>
<span title="777777"><input id="ctl00_PrimaryContent_repCustomers_ctl07_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl07$Customer" value="radCustomer" /></span>
</td>
<td>777777</td>
<td>Leonard's Lambchops</td>
</tr>
<tr>
<td>
<span title="888888"><input id="ctl00_PrimaryContent_repCustomers_ctl08_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl08$Customer" value="radCustomer" /></span>
</td>
<td>888888</td>
<td>Dave's Diamond Deli</td>
</tr>
<tr>
<td>
<span title="999999"><input id="ctl00_PrimaryContent_repCustomers_ctl09_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl09$Customer" value="radCustomer" /></span>
</td>
<td>999999</td>
<td>Ernie's Eatery</td>
</tr>
</table>
I finally got around this by creating a plain radio button and setting the value using an server-side eval.
<input type="radio" name="radCustomer" value='<%#Eval("CustomerNumber") %>' />
Now when the application performs a postback, I check for the value of Request.Form["radCustomer"]. This works flawlessly.
Unfortunately, this is a well known issue with radio buttons within a repeater. One of your only options would be to create a custom server control derived from the RadioButton class and override how it renders.
EDIT: Here's a sample of what the derived class may look like:
public class MyRadioButton : RadioButton
{
protected override void Render(HtmlTextWriter writer)
{
writer.Write("<input id=\"" + base.ClientID + "\" ");
writer.Write("type=\"radio\" ");
writer.Write("name=\"" + base.ID + "\" ");
writer.Write("value=\"" + base.ID + "\" />");
writer.Write("<label for=\"" + base.ClientID + "\">");
writer.Write(base.Text);
writer.Write("</label>");
}
}
I fixed it in javascript:
$(function () {
$("#divWithGridViewOrRepeater input:radio").attr("name", "yourGroupName");
});
I had the same issues. I am using Literal as placeholder to render radio button onItemCreated event.
ASP.Net
<asp:Repeater ID="rpt" runat="server" OnItemCreated="rpt_OnItemCreated">
<ItemTemplate>
<asp:Literal ID="lit" runat="server"></asp:Literal>
</ItemTemplate>
</asp:Repeater>
C#
protected void rpt_OnItemCreated(object sender, RepeaterItemEventArgs e) {
Literal lit = (Literal)e.Item.FindControl("lit");
lit.Text = "<input type=\"radio\" name=\"myGroup\">";
}
I had to modify slightly the answer posted above by r3dsky.
Here's what worked for me:
$(document).ready(function () {
$(".divWithGridViewOrRepeater input:radio").attr("name", "yourGroupName");
});
I would start by adding a value on my radiobutton Value='<%#Eval("CustomerNumber") %>'.
I made my radiobutton have autopostback set to true, and then in the event handler set all the other radio buttons to BE unselected.
Not ideal, but I need lots control over the visibility and enabled attributes of the radiobutton, and it seemed easier to let ASP.NET control that rather than resorting to client side script.
This is a well known bug with the ASP.NET Repeater using RadioButtons:
here best solution in my opinion
I did this:
$("input:radio").attr("name", $("input:radio").first().attr("name"));
Why? because if you replace the name property for any string you want, you will get an 'not found error'. So, you need to get the name of the first radiobutton, and rename all of them with that name. It works like a sharm ;)
My solution, similar to others:
<input id="ctlRadio" runat="server" type="radio" data-fixgroupbug="1" >
// Fixes this ASP.NET bug: if radio input is inside repeater you can't set its name.
// Every input gets set different name by ASP.NET.
// They don't behave as a group. You can select multiple radios.
function fixRadiogroupBug()
{
$('[type="radio"][data-fixgroupbug]').click(function () {
$(this).siblings('[type="radio"]').prop('checked', false);
});
}
$(document).ready(function () {
fixRadiogroupBug();
});