Get a Table column value into variable in C# - c#

I am getting a itemtemplate field of form view using a table. I need to get a username into a variable so that I can delete a particular row.Username is unique.
This is my code:
<ItemTemplate>
<table>
<tr>
<td align="right"><b>User Name:</b></td>
<td><%# Eval("UserName") %></td>
</tr>
<tr>
<td align="right"><b>Password:</b></td>
<td><%# Eval("Password") %></td>
</tr>
<tr>
<td align="right"><b>First Name:</b></td>
<td><%# Eval("FirstName") %></td>
</tr>
<tr>
<td align="right"><b>Last Name:</b></td>
<td><%# Eval("LastName") %></td>
</tr>
<tr>
<td colspan="2">
<asp:LinkButton ID="EditButton"
Text="Edit"
CommandName="Edit"
RunAt="server"/>
<asp:LinkButton ID="NewButton"
Text="New"
CommandName="New"
RunAt="server"/>
<asp:LinkButton ID="DeleteButton"
Text="Delete"
CommandName="Delete"
RunAt="server"/>
</td>
</tr>
</table>
</ItemTemplate>
How can I do it in C#?
Any help will be appreciated.

I would use a server control instead, for example a Label, then you can find it via item.FindControl:
aspx:
<tr>
<td align="right"><b>User Name:</b></td><td>
<asp:Label Id="LblUserName" runat="server"
Text='<%# Eval("UserName") %>'></asp:label>
</td>
</tr>
.......
<asp:LinkButton ID="DeleteButton"
Text="Delete"
CommandName="Delete"
RunAt="server"
OnCommand="DeleteButton_Command" />
codebehind:
void DeleteButton_Command(Object sender, CommandEventArgs e)
{
if(e.CommandName == "Delete")
{
LinkButton btnDelete = (LinkButton)sender;
var item = (FormViewItem)btnDelete.NamingContainer;
Label LblUserName = (Label)item.FindControl("LblUserName");
String userName = LblUserName.Text;
}
}

Related

asp.net - SelectItemTemplate doesn't work

I have two tables. First works fine - if button ID="Button1" CommandName="Select" pressed selected item turns red. But second table doesn't do the same if I pressed it's own button ID="Button2" CommandName="Select".
first table listView ID="ListViewGrSDtudents"
second table listView ID="ListViewGroups"
Does somebody now what why it doesn't work?
It's my .aspx code:
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<!-- Таблица групп -->
<div>
<asp:ListView ID="ListViewGroups"
runat="server"
ItemType="BD_Class_Library.studentGroup"
DataKeyNames="groupId"
SelectMethod="GetStudGroups"
InsertMethod="InsertStudGroup"
UpdateMethod="UpdateGroup"
DeleteMethod="DeleteGroup"
OnSelectedIndexChanged="ListViewGroups_SelectedIndexChanged">
<InsertItemTemplate>
<tr style="background-color: yellowgreen">
<td></td>
<td>
<input id="groupName" runat="server" value="<%# BindItem.groupName %>" /></td>
<td>
<asp:Button ID="Button1" Width="100%" CommandName="Insert" runat="server" Text="Вставить" />
</td>
</tr>
</InsertItemTemplate>
<EditItemTemplate>
<tr style="background-color: yellow">
<td><%# Item.groupId %></td>
<td>
<input id="groupName" runat="server" value="<%# BindItem.groupName %>" /></td>
<td>
<asp:Button CommandName="Update" runat="server" Text="Сохранить" />
<asp:Button CommandName="Cancel" runat="server" Text="Отмена" />
</td>
</tr>
</EditItemTemplate>
<LayoutTemplate>
<table border="1">
<tr style="background-color: darkgray">
<th>ID</th>
<th>Группа</th>
<th></th>
</tr>
<tr id="itemPlaceholder" runat="server"></tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="background-color: red">
<td><%# Item.groupId %></td>
<td><%# Item.groupName %></td>
<td>
<asp:Button CommandName="Edit" runat="server" Text="Изменить" />
<asp:Button CommandName="Delete" runat="server" Text="Удалить" />
</td>
</tr>
</SelectedItemTemplate>
<ItemTemplate>
<tr style="background-color: grey">
<td><%# Item.groupId %></td>
<td><%# Item.groupName %></td>
<td>
<asp:Button CommandName="Select" runat="server" Text="Выбрать" />
<asp:Button CommandName="Edit" runat="server" Text="Изменить" />
<asp:Button CommandName="Delete" runat="server" Text="Удалить" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</div>
<div>
<asp:ListView
ID="ListViewGrSDtudents"
runat="server"
ItemType="BD_Class_Library.student"
DataKeyNames="studId"
OnSelectedIndexChanging="ListViewGrSDtudents_SelectedIndexChanging"
OnSelectedIndexChanged="ListViewGrSDtudents_SelectedIndexChanged">
<SelectedItemTemplate>
<tr style="background-color: red">
<td><%# Item.studId %></td>
<td><%# Item.studFam %></td>
<td><%# Item.studName %></td>
<td><%# Item.studOtc %></td>
<td><%# Item.studBiletNum %></td>
</tr>
</SelectedItemTemplate>
<ItemTemplate>
<tr style="background-color: grey">
<td><%# Item.studId %></td>
<td><%# Item.studFam %></td>
<td><%# Item.studName %></td>
<td><%# Item.studOtc %></td>
<td><%# Item.studBiletNum %></td>
<td><asp:Button ID="Button2" CommandName="Select" runat="server" Text="Выбрать" /></td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table border="1" style="width: 60%">
<tr id="groupPlaceholder" runat="server"></tr>
<tr style="background-color: aqua">
<th>ID студента</th>
<th>Фамилия</th>
<th>Имя</th>
<th>Отчество</th>
<th>Студ. билет</th>
</tr>
<tr id="itemPlaceholder" runat="server" itemplaceholderid="itemPlaceholderStudent"></tr>
</table>
</LayoutTemplate>
<EmptyDataTemplate>
<table border="1" style="width: 60%">
<tr style="background-color: aqua">
<th>ID студента</th>
<th>Фамилия</th>
<th>Имя</th>
<th>Отчество</th>
<th>Студ. билет</th>
<th></th>
</tr>
<tr style="background-color: grey">
<td colspan="5" style="text-align: center">В данной группе нет студентов</<td>
</tr>
</table>
</EmptyDataTemplate>
</asp:ListView>
</div>
</form>
</body>
</html>
event - ListViewGrSDtudents_SelectedIndexChanged code:
protected void ListViewGrSDtudents_SelectedIndexChanged(object sender, EventArgs e)
{
int selStudent = (int)ListViewGrSDtudents.SelectedDataKey.Value;
Session["SelectedStudent"] = selStudent;
Session["SelectedStudentIndex"] = ListViewGrSDtudents.SelectedIndex;
Response.Redirect("~/Default.aspx");
}
Description Part 1
Description Part 2

select multiple items from listview and do action on button click

I have a listview, I want to select multiple items from the listview and on button click need to do some action on the rows selected.But I couldn't get the value item from the listview, below is the code I tried, where I'm doing wrong here?
Markup
<asp:ListView ID="LvOrders" runat="server"
GroupPlaceholderID="groupPlaceHolder1"
ItemPlaceholderID="itemPlaceHolder1"
OnPagePropertiesChanging="OnPagePropertiesChanging">
<LayoutTemplate>
<table id="product-master" class="table table-bordered table-striped">
<tr>
<th><asp:CheckBox ID="ChkBox" runat="server" /></th>
<th>Order #</th>
<th>User Name</th>
<th>Purchase Date</th>
<th>Amount</th>
</tr>
<asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder>
<tr>
<td colspan="3">
<asp:DataPager ID="DataPager1" runat="server"
class="btn-group btn-group-sm"
PagedControlID="LvOrders"
PageSize="10">
<Fields>
<asp:NextPreviousPagerField PreviousPageText="<"
FirstPageText="|<"
ShowPreviousPageButton="true"
ShowFirstPageButton="true"
ShowNextPageButton="false"
ShowLastPageButton="false"
ButtonCssClass="btn btn-default"
RenderNonBreakingSpacesBetweenControls="false"
RenderDisabledButtonsAsLabels="false" />
<asp:NumericPagerField ButtonType="Link"
CurrentPageLabelCssClass="btn btn-primary disabled"
RenderNonBreakingSpacesBetweenControls="false"
NumericButtonCssClass="btn btn-default"
ButtonCount="10"
NextPageText="..."
NextPreviousButtonCssClass="btn btn-default" />
<asp:NextPreviousPagerField NextPageText=">"
LastPageText=">|"
ShowNextPageButton="true"
ShowLastPageButton="true"
ShowPreviousPageButton="false"
ShowFirstPageButton="false"
ButtonCssClass="btn btn-default"
RenderNonBreakingSpacesBetweenControls="false"
RenderDisabledButtonsAsLabels="false" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder1">
</asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td><asp:CheckBox ID="ChkBx" runat="server" /></td>
<td><%# Eval("OrderNo") %></td>
<td><%# Eval("Name") %></td>
<td><%# Eval("Created") %></td>
<td><%# Eval("Amount") %></td>
</ItemTemplate>
</asp:ListView>
C# Code
string res;
protected void btnAssign_Click(object sender, EventArgs e)
{
foreach (ListViewItem row in LvOrders.Items)
{
CheckBox cb = (CheckBox)row.FindControl("ChkBox");
if (cb != null)
{
if (cb.Checked == true)
{
ListViewItem item = LvOrders.Items[LvOrders.SelectedIndex];
String c = item.FindControl("OrderNo").ToString();
res = res + "" + c;// printing selected OrderNo
}
}
}
}
You must assign an ID like this.
<ItemTemplate>
<td>
<asp:CheckBox ID="ChkBx" runat="server" />
</td>
<td>
<asp:label ID="OrderNo" runat="server"
Text='<%# Eval("OrderNo") %>'>
</asp:label>
</td>
<td><%# Eval("Name") %></td>
<td><%# Eval("Created") %></td>
<td><%# Eval("Amount") %></td>
</ItemTemplate>
Now in code-behind
CheckBox cb = (CheckBox)row.FindControl("ChkBox");
if (cb != null)
{
if (cb.Checked)
{
var OrderNoLabel = (Label)row.FindControl("OrderNo") ;
res = res + "" + OrderNoLabel.Text;// printing selected OrderNo
}
}
You had written item.FindControl("OrderNo").ToString();
But in you ASPX Page you had defined <td><%# Eval("OrderNo") %></td>
So, you had not defined any control and still want to find control. Hence this will cause error, the option is to use Label, in case you want to find the control and its value.
PS: Mark as answer, if it helped

Showing comments without reloading page

The code below get me a comment , puts it in the database and then waits for a page reload to show the comment. How can i make the submited comment to be shown right after it has been posted along with the new ones ? This is the code that does the stuff :
Layout:
<table>
<tr>
<td colspan="2">All Comments</td>
<td>
&nbsp
</td>
</tr>
<tr> <td colspan="2"> </td></tr>
<tr>
<td>
<asp:Repeater ID="Repeater1" runat="server" ItemType="SiteStiri.Models.Comments" SelectMethod="GetComments" >
<ItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label id="lblDate" runat="server" Text='<%# Item.ReleaseDate %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="lblComment" runat="server" Text='<%# Item.Comment %>'>
</asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
<AlternatingItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label id="Label1" runat="server" Text='<%# Item.ReleaseDate %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="Label2" runat="server" Text='<%# Item.Comment %>'>
</asp:Label>
</td>
</tr>
</table>
</AlternatingItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</td>
</tr>
<td>
<table>
<tr>
<td colspan="2" >Add Your Comment</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblStatus" runat="server" Visible="False"></asp:Label>
</td>
<td>
&nbsp
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox ID="txtcomment" runat="server" TextMode="MultiLine">
</asp:TextBox>
</td>
<td>
&nbsp
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</td>
<td>
&nbsp
</td>
</tr>
</table>
</table>
</td>
</tr>
</table>
Code Behind:
public void fnSubmitComment()
{
AddComment cmt = new AddComment();
String x = Request.QueryString["newsID"].ToString();
int y = Convert.ToInt32(x);
bool addSucces = cmt.Addcomment( y , txtcomment.Text);
if (addSucces)
{
lblStatus.Text = "Your Comment has been Added Successfully.";
}
else
{
lblStatus.Text = "Your Comment has not been Added.";
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
fnSubmitComment();
}
public IQueryable<Comments> GetComments()
{
var _db = new SiteStiri.Models.CommentsContext();
IQueryable<Comments> query = _db.Comments;
String x = Request.QueryString["newsID"].ToString();
int y = Convert.ToInt32(x);
query = query.Where(p => p.NewsID == y);
return query;
}
I heard i can do that with ajax ? (My knowledge about ajax is 0 currently) Any tips on how i can do this ?
You must wrapper you repeater in an updatepanel,
set UpdateMode="Conditional" and add a trigger on btnSubmit so when click the button the update the repeater with the normal page life cycle
Remember to bind the repeater after that you add the commet in the codebehind and must be present in your page a ScriptManager control
more or less thus
<asp:ScriptManager runat="server" />
<table>
<tr>
<td colspan="2">All Comments</td>
<td>&nbsp
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server" ItemType="SiteStiri.Models.Comments" SelectMethod="GetComments">
<ItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label ID="lblDate" runat="server" Text='<%# Item.ReleaseDate %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="lblComment" runat="server" Text='<%# Item.Comment %>'>
</asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
<AlternatingItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label ID="Label1" runat="server" Text='<%# Item.ReleaseDate %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="Label2" runat="server" Text='<%# Item.Comment %>'>
</asp:Label>
</td>
</tr>
</table>
</AlternatingItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td colspan="2">Add Your Comment</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblStatus" runat="server" Visible="False"></asp:Label>
</td>
<td>&nbsp
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox ID="txtcomment" runat="server" TextMode="MultiLine">
</asp:TextBox>
</td>
<td>&nbsp
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</td>
<td>&nbsp
</td>
</tr>
</table>
</td>
</tr>
</table>

How to retrieve TD value of table column (ID) which is inside a repeater

I have a repeater with a HTML Table layout as follows where it fills from the database dynamically,
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<th colspan="2"></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "QuestionId") %> <asp:HiddenField ID="hiddenField" Value='<%# DataBinder.Eval(Container.DataItem, "QuestionId") %>' runat="server" /> </td>
<td>
<table>
<tr>
<td colspan="4"><%# DataBinder.Eval(Container.DataItem, "Question") %> </td>
</tr>
<tr><td><asp:RadioButton ID="op1" runat="server" OnCheckedChange="check_Answer"/></td><td><%# DataBinder.Eval(Container.DataItem, "Answer1") %> </td></tr>
<tr><td><asp:RadioButton ID="op2" runat="server" OnCheckedChange="check_Answer"/></td><td><%# DataBinder.Eval(Container.DataItem, "Answer2") %> </td></tr>
<tr><td><asp:RadioButton ID="op3" runat="server" OnCheckedChange="check_Answer"/></td><td><%# DataBinder.Eval(Container.DataItem, "Answer3") %> </td></tr>
<tr><td><asp:RadioButton ID="op4" runat="server" OnCheckedChange="check_Answer"/></td><td><%# DataBinder.Eval(Container.DataItem, "Answer4") %> </td></tr>
</table>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
In Code Behind
protected void check_Answer(object sender, EventArgs e)
{
RepeaterItem item = (sender as RadioButton).Parent as RepeaterItem;
HiddenField hiddenField = item.FindControl("hiddenField") as HiddenField;
String questionId = hiddenField.Value;
Session["test"] = questionId;/*Just added to a session and passed to test page*/
Response.Redirect("test.aspx");/*This Page Displays the value of Session["test"]*/
}
Now what I need to do is OnCheckedChange event for the radio buttons it calls a code behind method, but should pass the QuestionID value to the method. Please suggest me a way to retrieve the value which contains the "QuestionID". For More Information the real interface looks like below,
You can group option buttons and use questionid as a part of group name. In the code you can get the questionid from GroupName. So you don't really need any hidden field. Your markup may look like below:
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<th colspan="2"></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "QuestionId") %> </td>
<td>
<table>
<tr>
<td colspan="4"><%# DataBinder.Eval(Container.DataItem, "Question") %> </td>
</tr>
<tr>
<td>
<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="true" Text='<%# DataBinder.Eval(Container.DataItem, "Answer1") %>'
OnCheckedChanged="check_Answer" GroupName='<%# Eval("QuestionId","Grp_{0}") %>' />
</td>
<td><asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="true" Text='<%# DataBinder.Eval(Container.DataItem, "Answer2") %>'
OnCheckedChanged="check_Answer" GroupName='<%# Eval("QuestionId","Grp_{0}") %>' />
</td>
<td><asp:RadioButton ID="RadioButton3" runat="server" AutoPostBack="true" Text='<%# DataBinder.Eval(Container.DataItem, "Answer3") %>'
OnCheckedChanged="check_Answer" GroupName='<%# Eval("QuestionId","Grp_{0}") %>' />
</td>
<td><asp:RadioButton ID="RadioButton4" runat="server" AutoPostBack="true" Text='<%# DataBinder.Eval(Container.DataItem, "Answer4") %>'
OnCheckedChanged="check_Answer" GroupName='<%# Eval("QuestionId","Grp_{0}") %>' />
</td>
</tr>
</table>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
And in the code:
protected void check_Answer(object sender, EventArgs e)
{
string grpId = ((RadioButton)sender).GroupName;
string questionId = grpId.Split('_')[1].ToString();
Session["test"] = questionId;/*Just added to a session and passed to test page*/
Response.Redirect("test.aspx");/*This Page Displays the value of Session["test"]*/
}
I would add hidden field as below
<asp:HiddenField ID="hiddenField" Value='<%# DataBinder.Eval(Container.DataItem, "QuestionId") %>' runat="server" />
in your check_Answer event
RepeaterItem item = (sender as RadioButton).Parent as RepeaterItem;
HiddenField hiddenField = item.FindControl("hiddenField") as HiddenField;
string questionId= hiddenField.Value;

Table display issue

I got a table with 2 nested tables inside that display my two repeaters. My repeaters display Home and office addresses respectively. The problem is that whenever I add a new record in one repeater, the other repeater table's display gets messed up. Like if I add a record in rpt1 , then table for rpt1 moves up and table for rpt2 goes down..ie the headers do not display in one single line . They move up and down when records are added or deleted. WHat I want is these headers to be fixed so if I add new records or delete records, the headings of both repeaters display on the same line...How do I fix this ? Hope its not confusing.
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%">
<asp:Panel ID="pnlAddAddress" runat="server">
<asp:Repeater ID="rpt1" OnItemCommand="rpt1_ItemCommand" runat="server" OnItemDataBound="rpt1_OnItemDataBound">
<HeaderTemplate>
<table width="99%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5" class="linegrey">
</td>
</tr>
<tr class="lgrey">
<td>
Address1
</td>
<td>
City
</td>
<td>
State
</td>
<td>
IsDefault
</td>
<td>
Actions
</td>
</tr>
<tr>
<td colspan="5" class="dots">
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lnkAddressB" runat="server" Text='<%# Eval("Address1")%>' CommandName="DisplayAddressB" CommandArgument='<%#Eval("AddID") %>' CausesValidation=false></asp:LinkButton>
</td>
<td>
<%# Eval("City")%>
</td>
<td>
<%# Eval("State")%>
</td>
<td>
<%-- Visible='<%# Eval("IsDefault")%>'--%>
<asp:LinkButton ID="lnkDefaultB" Text="Set as Default" CommandName="SetDefaultB" runat="server" CommandArgument='<%# Eval("AddID") + "," + Eval("IsB") %>'
CausesValidation="false" Visible='<%# Eval("IsDefault")%>'></asp:LinkButton>
<asp:Label ID="labelDefaultB" Text="Yes" runat="server" Visible='<%# Eval("IsDefault")%>'></asp:Label>
</td>
<td>
<asp:ImageButton ID="lnkAdd" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Edit" runat="server" ImageUrl="~/images/Edit.gif" Width="14" Height="14" ToolTip="Edit"></asp:ImageButton>
<asp:ImageButton ID="lnkDel" Text="Delete" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Delete" runat="server" ImageUrl="~/images/Delete.gif" Width="14" Height="14" ToolTip="Delete"></asp:ImageButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</td>
<td>
<asp:Panel ID="pnlSping" runat="server">
<asp:Repeater ID="rpt12" OnItemCommand="rpt12_ItemCommand" runat="server" OnItemDataBound="rptSpping_OnItemDataBound">
<HeaderTemplate>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5" class="linegrey">
</td>
</tr>
<tr class="lgrey">
<td>
Address1
</td>
<td>
City
</td>
<td>
State
</td>
<td>
IsDefault
</td>
<td>
Actions
</td>
</tr>
<tr>
<td colspan="5" class="dots">
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lnkAddressS" runat="server" Text='<%# Eval("Address1")%>' CommandArgument='<%#Eval("AddID") %>' CommandName="DisplayAddressS" CausesValidation="false"></asp:LinkButton>
</td>
<td>
<%# Eval("City")%>
</td>
<td>
<%# Eval("State")%>
</td>
<td>
<asp:LinkButton ID="lnkDefaultS" Text="Set as Default" CommandName="SetDefaultS" runat="server" Visible=true CommandArgument='<%# Eval("AddID") + "," + Eval("IsS") %>'
CausesValidation="false"></asp:LinkButton>
<asp:Label ID="labelDefaultS" Text="Yes" runat="server" Visible=true></asp:Label>
</td>
<td>
<asp:ImageButton ID="lnkAdd" Text="Edit" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Edit" runat="server" ImageUrl="~/images/Edit.gif" Width="14" Height="14" ToolTip="Edit"></asp:ImageButton>
<asp:ImageButton ID="lnkDel" Text="Delete" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Delete" runat="server" ImageUrl="~/images/Delete.gif" Width="14" Height="14" ToolTip="Delete"></asp:ImageButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</td>
</tr>
</table>
Use css attribute valign and set its value to top like this <td width="50%" valign="top">.
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%" valign="top">
<asp:Panel ID="pnlAddAddress" runat="server">
......
</asp:Panel>
</td>
<td valign="top">
<asp:Panel ID="pnlSping" runat="server">
......
</asp:Panel>
</td>
</tr>
</table>
For headers look to use the <th> element, this will keep them at the top of the table.
Put the <table> tags you do have outside your repeater controls, make sure the repeater only renders a single row and the same for the header.
Unless you have good reason consider just wrapping the two tables in <div> tags as nested tables really don't work ideally for layout.

Categories