Below is the listview with html input radio buttons.The radio buttons are generated dynamically based on certain condition.
<asp:ListView ID="MyListView" runat="server" DataKeyNames="MyKeyName"
OnItemDataBound="MyListView_ItemDataBound">
<LayoutTemplate>
<div id="Div1" runat="server">
<div id="itemPlaceholder" runat="server">
</div>
</div>
</LayoutTemplate>
<EmptyDataTemplate>
<div id="Div2" runat="server">
<div id="itemPlaceholder" runat="server">
No data was returned.
</div>
</div>
</EmptyDataTemplate>
<ItemTemplate>
<span class="custom-time">
<input type="radio" id="MyRadioButton" name="MyRadioButton" value='<%# Eval("MyKeyName") %>'
runat="server" onclick="Redirect(this.value)" />
<asp:Label AssociatedControlID="MyRadioButton" runat="server" Text='<%# Eval("MyKeyNameString") %>'></asp:Label>
<span class="box"><span class="tick"></span></span></span>
</ItemTemplate>
</asp:ListView>
In the aspx.cs page to code to disable the input radio button would be something like this
protected void MysListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
if (e.Item.ItemType == ListViewItemType.DataItem)
{
HtmlInputRadioButton oRadioButton = (HtmlInputRadioButton)dataItem.FindControl("MyRadioButton");
if (oRadioButton != null && (oRadioButton.Value == "MyCondition"))
oRadioButton.Attributes["disabled"] = "disabled";
}
}
So when the page renders you would see the below html
<input value="MyKeyNameValue" name="MyListView$ctrl2$MyRadioButton" type="radio" id="MyListView_ctrl2_MyRadioButton" onclick="Redirect(this.value)" disabled="disabled" class="completed" />
<asp:ListView ID="MyListView" runat="server" DataKeyNames="MyKeyName"
OnItemDataBound="MyListView_ItemDataBound">
<LayoutTemplate>
<div id="Div1" runat="server">
<div id="itemPlaceholder" runat="server">
</div>
</div>
</LayoutTemplate>
<EmptyDataTemplate>
<div id="Div2" runat="server">
<div id="itemPlaceholder" runat="server">
No data was returned.
</div>
</div>
</EmptyDataTemplate>
<ItemTemplate>
<span class="custom-time">
<input type="radio" id="MyRadioButton" name="MyRadioButton" value='<%# Eval("MyKeyName") %>'
runat="server" onclick="Redirect(this.value)" />
<asp:Label AssociatedControlID="MyRadioButton" runat="server" Text='<%# Eval("MyKeyNameString") %>'></asp:Label>
<span class="box"><span class="tick"></span></span></span>
</ItemTemplate>
</asp:ListView>
In the aspx.cs page to code to disable the input radio button would be something like this
protected void MysListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
if (e.Item.ItemType == ListViewItemType.DataItem)
{
HtmlInputRadioButton oRadioButton = (HtmlInputRadioButton)dataItem.FindControl("MyRadioButton");
if (oRadioButton != null && (oRadioButton.Value == "MyCondition"))
oRadioButton.Attributes["disabled"] = "disabled";
}
}
So when the page renders you would see the below html
<input value="MyKeyNameValue" name="MyListView$ctrl2$MyRadioButton" type="radio" id="MyListView_ctrl2_MyRadioButton" onclick="Redirect(this.value)" disabled="disabled" class="completed" />
No comments:
Post a Comment