Thursday, May 22, 2014
Use of Javascript to allow RadioButton grouping to work in Repeater
1.) JavaScript
<script language="javascript" type="text/javascript">
function RadioSelectionChanged(groupName, current) {
var group = document.getElementsByName(groupName);
for (i = 0; i < group.length; i++) {
//.NET uses a span tag to define the control "name", so the first control in the span control will be the radiobutton if(group[i].childNodes.length > 0 && group[i].childNodes[0].type == 'radio')
group[i].childNodes[0].checked = false;
} current.checked = true;
}</script>
2.) Control
<asp:Repeater ID="Rptr" runat="server">
<ItemTemplate>
<asp:RadioButton ID="Rb" runat="server" onclick="RadioSelectionChanged('GroupName', this);" name="GroupName" />
</ItemTemplate>
</asp:Repeater>
Wednesday, May 21, 2014
Convert class to DataRow
To convert a class instance to a DataRow
public DataRow ConvertClassToDataRow(ClassName theClass)
{
DataTable table = new DataTable();
DataRow row = table.NewRow();
PropertyInfo[] properties = theClass.GetType().GetProperties();
foreach (PropertyInfo property in properties)
{
DataColumn col = new DataColumn(property.Name, property.PropertyType);
table.Columns.Add(col); row[property.Name] = property.GetValue(theClass, null);
}
return row;
}
Subscribe to:
Posts (Atom)