S
Sam Solomon
Dear All,
I have a DataList which I have placed inside a table. The last column of the
dataList consist of a button called select.What I want to do is that when I
press the select button it should change the colour of that row and the
button "Select " changes into "Unselect". And when i press unselect its
colour changes back to white. I am able to change the colour back to white.
But when I press button select
it only changes the first <td> of that specific row. Below is my code:
<form id="Form1" method="post" runat="server">
<asp:datalist id="DataList1" style="Z-INDEX: 101; LEFT: 8px; POSITION:
absolute; TOP: 8px" runat="server" GridLines="Both"
SelectedItemStyleBackColor="#ff9900"
OnItemCommand="DataList1_ItemCommand"
<HeaderTemplate>
<table>
</HeaderTemplate>
<SelectedItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"SupplierID")%>
<%#DataBinder.Eval(Container.DataItem,"CompanyName")%>
<%#DataBinder.Eval(Container.DataItem,"ContactName")%>
<%#DataBinder.Eval(Container.DataItem,"ContactTitle")%>
<asp:Button ID="btnUnSelect" CommandName="UnSelect" Text="UnSelect"
Runat="server"></asp:Button>
</SelectedItemTemplate>
<ItemTemplate>
<tr>
<td><%#DataBinder.Eval(Container.DataItem,"SupplierID")%></td>
<td><%#DataBinder.Eval(Container.DataItem,"CompanyName")%></td>
<td><%#DataBinder.Eval(Container.DataItem,"ContactName")%></td>
<td><%#DataBinder.Eval(Container.DataItem,"ContactTitle")%></td>
<td><asp:Button ID="btnSelect" CommandName="Select" Text="Select"
Runat="server"></asp:Button></td></tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:datalist></form>
private void Page_Load(object sender, System.EventArgs e)
{
if(!PostBack)
{
BindDataList();
}
}
protected void DataList1_ItemCommand(Object s,DataListCommandEventArgs e)
{
if(e.CommandName=="Select")
{
DataList1.SelectedIndex = e.Item.ItemIndex;
}
else
DataList1.SelectedIndex = -1;
BindDataList();
}
If I remove the table tag.then It works fine.But I really want the table tag
to be in. because my Datalist then looks more neat and organized.
Any help will be much appreciated.
cheers,
Sunil Sabir
I have a DataList which I have placed inside a table. The last column of the
dataList consist of a button called select.What I want to do is that when I
press the select button it should change the colour of that row and the
button "Select " changes into "Unselect". And when i press unselect its
colour changes back to white. I am able to change the colour back to white.
But when I press button select
it only changes the first <td> of that specific row. Below is my code:
<form id="Form1" method="post" runat="server">
<asp:datalist id="DataList1" style="Z-INDEX: 101; LEFT: 8px; POSITION:
absolute; TOP: 8px" runat="server" GridLines="Both"
SelectedItemStyleBackColor="#ff9900"
OnItemCommand="DataList1_ItemCommand"
<HeaderTemplate>
<table>
</HeaderTemplate>
<SelectedItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"SupplierID")%>
<%#DataBinder.Eval(Container.DataItem,"CompanyName")%>
<%#DataBinder.Eval(Container.DataItem,"ContactName")%>
<%#DataBinder.Eval(Container.DataItem,"ContactTitle")%>
<asp:Button ID="btnUnSelect" CommandName="UnSelect" Text="UnSelect"
Runat="server"></asp:Button>
</SelectedItemTemplate>
<ItemTemplate>
<tr>
<td><%#DataBinder.Eval(Container.DataItem,"SupplierID")%></td>
<td><%#DataBinder.Eval(Container.DataItem,"CompanyName")%></td>
<td><%#DataBinder.Eval(Container.DataItem,"ContactName")%></td>
<td><%#DataBinder.Eval(Container.DataItem,"ContactTitle")%></td>
<td><asp:Button ID="btnSelect" CommandName="Select" Text="Select"
Runat="server"></asp:Button></td></tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:datalist></form>
private void Page_Load(object sender, System.EventArgs e)
{
if(!PostBack)
{
BindDataList();
}
}
protected void DataList1_ItemCommand(Object s,DataListCommandEventArgs e)
{
if(e.CommandName=="Select")
{
DataList1.SelectedIndex = e.Item.ItemIndex;
}
else
DataList1.SelectedIndex = -1;
BindDataList();
}
If I remove the table tag.then It works fine.But I really want the table tag
to be in. because my Datalist then looks more neat and organized.
Any help will be much appreciated.
cheers,
Sunil Sabir