Have 2 questions, but the error first. When I select the edit button after changed the rule name, no values are put into my newValues hashtable. So my edit never takes place. Other question is I have 2 controls to help create 1 item for a column during edit. How would I combine the control values during the edit. The two controls are a datepicker and a timeselector control.
Code Behind
protected void ruleLV_NeedDataSource(object sender, RadListViewNeedDataSourceEventArgs e)
{
ruleLV.DataSource = dt;
}
protected void ruleLV_ItemCommand(object sender, RadListViewCommandEventArgs e)
{
if (e.CommandName == RadListView.CancelCommandName)
{
ruleLV.InsertItemPosition = RadListViewInsertItemPosition.None;
// ruleLV.FindControl("Button1").Visible = true;
}
else if (e.CommandName == RadListView.UpdateCommandName)
{
RadListViewEditableItem item = (RadListViewEditableItem)e.ListViewItem;
Hashtable newValues = new Hashtable();
item.ExtractValues(newValues);
DataTable newDT = dt;
DataRow[] changedRows = newDT.Select("RuleID = " + e.ListViewItem.OwnerListView.DataKeyValues[e.ListViewItem.OwnerListView.EditIndexes[0]]["RuleID"].ToString());
if (changedRows.Length != 1)
{
e.Canceled = true;
return;
}
changedRows[0].BeginEdit();
try
{
foreach (DictionaryEntry entry in newValues)
{
changedRows[0][(string)entry.Key] = entry.Value;
}
changedRows[0].CancelEdit();
this.ViewState["_lvds"] = newDT;
}
catch (Exception ex)
{
changedRows[0].CancelEdit();
e.Canceled = true;
}
}
}
MarkUp
<telerik:RadListView ID="ruleLV" runat="server" AllowPaging="True"
DataKeyNames="RuleID" ItemPlaceholderID="RulePlaceHolder"
onitemcommand="ruleLV_ItemCommand" onneeddatasource="ruleLV_NeedDataSource"
PageSize="5" Skin="Windows7">
<LayoutTemplate>
<table ID="Table1" runat="server">
<tr>
<th ID="SummaryIdHdr" runat="server" width="150px">
Rule ID</th>
<th ID="BegTimeStampHdr" runat="server" width="200px">
Start Date/Time</th>
<th ID="EndTimeStampHdr" runat="server" width="200px">
End Date/Time</th>
</tr>
<tr ID="RulePlaceHolder" runat="server">
</tr>
</table>
<fieldset style="text-align: center; background-color: white;">
</fieldset>
</LayoutTemplate>
<EditItemTemplate>
<tr ID="rules" runat="server" bgcolor="white">
<td>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("SummaryID") %>'> </asp:TextBox>
</td>
<td>
<telerik:RadDatePicker ID="startDate" runat="server"
Calendar-ShowRowHeaders="false" SelectedDate='<%# Bind("BegTimeStamp") %>'>
</telerik:RadDatePicker>
</td>
<td>
<MKB:TimeSelector ID="time1" runat="server" Date='<%# Bind("BegTimeStamp") %>'
MinuteIncrement="1">
</MKB:TimeSelector>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("BegTimeStamp") %>'></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("EndTimeStamp") %>'></asp:TextBox>
</td>
<td>
<asp:Button ID="Button1" runat="server" CommandName="Update" Text="Update"
Width="70px" />
</td>
<td>
<asp:Button ID="Button2" runat="server" CausesValidation="false"
CommandName="Cancel" Text="Cancel" Width="70px" />
</td>
</tr>
</EditItemTemplate>
<ItemTemplate>
<tr ID="rules0" runat="server" bgColor="White">
<td>
<%#Eval("SummaryID") %></td>
<td>
<%#Eval("BegTimeStamp") %></td>
<td>
<%#Eval("EndTimeStamp") %></td>
<td>
<asp:Button ID="Button1" runat="server" CommandName="Edit" Text="Edit" />
</td>
</tr>
</ItemTemplate>
</telerik:RadListView>
<telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="ruleLV"
PageSize="1" Width="550px">
<Fields>
<telerik:RadDataPagerButtonField FieldType="FirstPrev" />
<telerik:RadDataPagerButtonField FieldType="Numeric" />
<telerik:RadDataPagerButtonField FieldType="NextLast" />
<telerik:RadDataPagerPageSizeField />
</Fields>
</telerik:RadDataPager>
Code Behind
protected void ruleLV_NeedDataSource(object sender, RadListViewNeedDataSourceEventArgs e)
{
ruleLV.DataSource = dt;
}
protected void ruleLV_ItemCommand(object sender, RadListViewCommandEventArgs e)
{
if (e.CommandName == RadListView.CancelCommandName)
{
ruleLV.InsertItemPosition = RadListViewInsertItemPosition.None;
// ruleLV.FindControl("Button1").Visible = true;
}
else if (e.CommandName == RadListView.UpdateCommandName)
{
RadListViewEditableItem item = (RadListViewEditableItem)e.ListViewItem;
Hashtable newValues = new Hashtable();
item.ExtractValues(newValues);
DataTable newDT = dt;
DataRow[] changedRows = newDT.Select("RuleID = " + e.ListViewItem.OwnerListView.DataKeyValues[e.ListViewItem.OwnerListView.EditIndexes[0]]["RuleID"].ToString());
if (changedRows.Length != 1)
{
e.Canceled = true;
return;
}
changedRows[0].BeginEdit();
try
{
foreach (DictionaryEntry entry in newValues)
{
changedRows[0][(string)entry.Key] = entry.Value;
}
changedRows[0].CancelEdit();
this.ViewState["_lvds"] = newDT;
}
catch (Exception ex)
{
changedRows[0].CancelEdit();
e.Canceled = true;
}
}
}
MarkUp
<telerik:RadListView ID="ruleLV" runat="server" AllowPaging="True"
DataKeyNames="RuleID" ItemPlaceholderID="RulePlaceHolder"
onitemcommand="ruleLV_ItemCommand" onneeddatasource="ruleLV_NeedDataSource"
PageSize="5" Skin="Windows7">
<LayoutTemplate>
<table ID="Table1" runat="server">
<tr>
<th ID="SummaryIdHdr" runat="server" width="150px">
Rule ID</th>
<th ID="BegTimeStampHdr" runat="server" width="200px">
Start Date/Time</th>
<th ID="EndTimeStampHdr" runat="server" width="200px">
End Date/Time</th>
</tr>
<tr ID="RulePlaceHolder" runat="server">
</tr>
</table>
<fieldset style="text-align: center; background-color: white;">
</fieldset>
</LayoutTemplate>
<EditItemTemplate>
<tr ID="rules" runat="server" bgcolor="white">
<td>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("SummaryID") %>'> </asp:TextBox>
</td>
<td>
<telerik:RadDatePicker ID="startDate" runat="server"
Calendar-ShowRowHeaders="false" SelectedDate='<%# Bind("BegTimeStamp") %>'>
</telerik:RadDatePicker>
</td>
<td>
<MKB:TimeSelector ID="time1" runat="server" Date='<%# Bind("BegTimeStamp") %>'
MinuteIncrement="1">
</MKB:TimeSelector>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("BegTimeStamp") %>'></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("EndTimeStamp") %>'></asp:TextBox>
</td>
<td>
<asp:Button ID="Button1" runat="server" CommandName="Update" Text="Update"
Width="70px" />
</td>
<td>
<asp:Button ID="Button2" runat="server" CausesValidation="false"
CommandName="Cancel" Text="Cancel" Width="70px" />
</td>
</tr>
</EditItemTemplate>
<ItemTemplate>
<tr ID="rules0" runat="server" bgColor="White">
<td>
<%#Eval("SummaryID") %></td>
<td>
<%#Eval("BegTimeStamp") %></td>
<td>
<%#Eval("EndTimeStamp") %></td>
<td>
<asp:Button ID="Button1" runat="server" CommandName="Edit" Text="Edit" />
</td>
</tr>
</ItemTemplate>
</telerik:RadListView>
<telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="ruleLV"
PageSize="1" Width="550px">
<Fields>
<telerik:RadDataPagerButtonField FieldType="FirstPrev" />
<telerik:RadDataPagerButtonField FieldType="Numeric" />
<telerik:RadDataPagerButtonField FieldType="NextLast" />
<telerik:RadDataPagerPageSizeField />
</Fields>
</telerik:RadDataPager>