Hi,
I have a Radgrid inside userControl.
I have a select column, and a "delete selected" link.
When user click on "delete selected" --> delete all items selected.
But I have a problem, the items seleted are null.. I tried use AjaxPanel but does not work
thi. is my ascx code
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
<telerik:RadGrid runat="server" ID="MyGrid" AutoGenerateColumns="false" Skin="Vista"
RegisterWithScriptManager="false" AllowMultiRowSelection="True" >
<MasterTableView DataKeyNames="Id" CommandItemDisplay="Top" EditMode="InPlace">
<Columns>
<telerik:GridClientSelectColumn CommandName="Select" UniqueName="Select" HeaderStyle-Width="30px"
Resizable="false" >
</telerik:GridClientSelectColumn>
<telerik:GridEditCommandColumn HeaderStyle-Width="25px" UniqueName="EditCommandColumn"
ButtonType="ImageButton" EditImageUrl="/UI/Images/grid_edit.png" Resizable="false">
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn UniqueName="btnDelete" ConfirmDialogType="RadWindow" ButtonType="ImageButton"
CommandName="Delete" ConfirmDialogHeight="100px" ConfirmDialogWidth="300px" HeaderStyle-Width="25px"
Resizable="false" />
<telerik:GridTemplateColumn DataField="Id" HeaderText="Id" UniqueName="Id" Visible="false" ConvertEmptyStringToNull="true">
<InsertItemTemplate>
<telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Id") %> '
Width="150px" ReadOnly="true" Enabled="false" CssClass="labelGrid" />
</InsertItemTemplate>
<EditItemTemplate>
<telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Id") %> '
Width="150px" CssClass="labelGrid" ReadOnly="true" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="Value" DataField="Value">
<EditItemTemplate>
<asp:TextBox ID="txtValue" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Value") %>'
CssClass="textBoxInline"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="rfvValue" runat="server" ErrorMessage="*" Display="Dynamic"
ControlToValidate="txtValue" CssClass="validator"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="reValue" ControlToValidate="txtValue" runat="server"
ValidationExpression="^[0-9a-zA-Z]{1,125}$" CssClass="validator" Display="Dynamic"
SetFocusOnError="true"></asp:RegularExpressionValidator>
<asp:CustomValidator ID="cvValue" runat="server" SetFocusOnError="true" CssClass="validator"
OnServerValidate="cvValue_ServerValidate"></asp:CustomValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblValue" runat="server" Width="200px" CssClass="labelGrid" Text='<%# DataBinder.Eval(Container.DataItem, "Value") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<CommandItemTemplate>
<div class="quickAdd">
<asp:LinkButton ID="lnkqQuitInsert" runat="server" CommandName="InitInsert">
<asp:ImageButton ID="imgQuickAdd" runat="server" ImageUrl="/UI/Images/add.png" />
<asp:Label ID="lblQuickAdd" runat="server" /></asp:LinkButton>
<asp:LinkButton ID="lnkImport" runat="server" CommandName="Import">
<asp:ImageButton ID="imgImportFromtxt" runat="server" ImageUrl="/UI/Images/import_to_grid.png" />
<asp:Label ID="lblImportFromFile" runat="server" /></asp:LinkButton>
<asp:LinkButton ID="lnkDeleteSelected" runat="server" CommandName="DeleteSelected">
<asp:ImageButton ID="imgDeleteSelected" runat="server" ImageUrl="/UI/Images/delete_selected.png" />
<asp:Label ID="lblDeleteSelected" runat="server" /></asp:LinkButton>
<asp:LinkButton ID="lnkDeleteAllValues" runat="server" CommandName="DeleteAllValues">
<asp:ImageButton ID="imgDeleteAllValues" runat="server" ImageUrl="/UI/Images/delete_all.png" />
<asp:Label ID="lblDeleteAllValues" runat="server" /></asp:LinkButton>
</div>
</CommandItemTemplate>
</MasterTableView>
<ClientSettings>
<Selecting AllowRowSelect="true" />
</ClientSettings>
</telerik:RadGrid>
</telerik:RadAjaxPanel>
ascx.cs
protected void MyGrid_ItemCommand(object source, GridCommandEventArgs e)
{
case "DeleteSelected":
List<int> listValuesId= new List<int>();
List<smListValues> listValues = (List<smListValues>)Session["Data"];
foreach (GridDataItem item in MyGrid.MasterTableView.GetSelectedItems())
{
// this generate an error --> values is Null
// Hashtable values = new Hashtable();
//item.ExtractValues(values);
string strTxt = item["Id"].Text; --> tthis return  
//if (values["Id"].ToString() == " " || string.IsNullOrEmpty(values["Id"].ToString()))
//{
// LogConfig.SaveInFile(Level.Debug, "Item does not exist in db", null, "ListMask.ascx.cs", "ItemCommand");
// string valueKey = values["Value"].ToString();
// listValues.Remove(listValues.Find(x => x.Value ==valueKey));
//}else
//{
// listValuesId.Add(Convert.ToInt32(values["Id"].ToString()));
// listValues.Remove(listValues.Find(x => x.Id == Convert.ToInt32(values["Id"].ToString())));
//}
}
new smListValues().DeleteValues(listValuesId, Convert.ToInt64(Session["ListId"]));
Session["Data"] = listValues;
MyGrid.Rebind();
break;
}
What I do wrong??
I have a Radgrid inside userControl.
I have a select column, and a "delete selected" link.
When user click on "delete selected" --> delete all items selected.
But I have a problem, the items seleted are null.. I tried use AjaxPanel but does not work
thi. is my ascx code
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
<telerik:RadGrid runat="server" ID="MyGrid" AutoGenerateColumns="false" Skin="Vista"
RegisterWithScriptManager="false" AllowMultiRowSelection="True" >
<MasterTableView DataKeyNames="Id" CommandItemDisplay="Top" EditMode="InPlace">
<Columns>
<telerik:GridClientSelectColumn CommandName="Select" UniqueName="Select" HeaderStyle-Width="30px"
Resizable="false" >
</telerik:GridClientSelectColumn>
<telerik:GridEditCommandColumn HeaderStyle-Width="25px" UniqueName="EditCommandColumn"
ButtonType="ImageButton" EditImageUrl="/UI/Images/grid_edit.png" Resizable="false">
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn UniqueName="btnDelete" ConfirmDialogType="RadWindow" ButtonType="ImageButton"
CommandName="Delete" ConfirmDialogHeight="100px" ConfirmDialogWidth="300px" HeaderStyle-Width="25px"
Resizable="false" />
<telerik:GridTemplateColumn DataField="Id" HeaderText="Id" UniqueName="Id" Visible="false" ConvertEmptyStringToNull="true">
<InsertItemTemplate>
<telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Id") %> '
Width="150px" ReadOnly="true" Enabled="false" CssClass="labelGrid" />
</InsertItemTemplate>
<EditItemTemplate>
<telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Id") %> '
Width="150px" CssClass="labelGrid" ReadOnly="true" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="Value" DataField="Value">
<EditItemTemplate>
<asp:TextBox ID="txtValue" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Value") %>'
CssClass="textBoxInline"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="rfvValue" runat="server" ErrorMessage="*" Display="Dynamic"
ControlToValidate="txtValue" CssClass="validator"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="reValue" ControlToValidate="txtValue" runat="server"
ValidationExpression="^[0-9a-zA-Z]{1,125}$" CssClass="validator" Display="Dynamic"
SetFocusOnError="true"></asp:RegularExpressionValidator>
<asp:CustomValidator ID="cvValue" runat="server" SetFocusOnError="true" CssClass="validator"
OnServerValidate="cvValue_ServerValidate"></asp:CustomValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblValue" runat="server" Width="200px" CssClass="labelGrid" Text='<%# DataBinder.Eval(Container.DataItem, "Value") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<CommandItemTemplate>
<div class="quickAdd">
<asp:LinkButton ID="lnkqQuitInsert" runat="server" CommandName="InitInsert">
<asp:ImageButton ID="imgQuickAdd" runat="server" ImageUrl="/UI/Images/add.png" />
<asp:Label ID="lblQuickAdd" runat="server" /></asp:LinkButton>
<asp:LinkButton ID="lnkImport" runat="server" CommandName="Import">
<asp:ImageButton ID="imgImportFromtxt" runat="server" ImageUrl="/UI/Images/import_to_grid.png" />
<asp:Label ID="lblImportFromFile" runat="server" /></asp:LinkButton>
<asp:LinkButton ID="lnkDeleteSelected" runat="server" CommandName="DeleteSelected">
<asp:ImageButton ID="imgDeleteSelected" runat="server" ImageUrl="/UI/Images/delete_selected.png" />
<asp:Label ID="lblDeleteSelected" runat="server" /></asp:LinkButton>
<asp:LinkButton ID="lnkDeleteAllValues" runat="server" CommandName="DeleteAllValues">
<asp:ImageButton ID="imgDeleteAllValues" runat="server" ImageUrl="/UI/Images/delete_all.png" />
<asp:Label ID="lblDeleteAllValues" runat="server" /></asp:LinkButton>
</div>
</CommandItemTemplate>
</MasterTableView>
<ClientSettings>
<Selecting AllowRowSelect="true" />
</ClientSettings>
</telerik:RadGrid>
</telerik:RadAjaxPanel>
ascx.cs
protected void MyGrid_ItemCommand(object source, GridCommandEventArgs e)
{
case "DeleteSelected":
List<int> listValuesId= new List<int>();
List<smListValues> listValues = (List<smListValues>)Session["Data"];
foreach (GridDataItem item in MyGrid.MasterTableView.GetSelectedItems())
{
// this generate an error --> values is Null
// Hashtable values = new Hashtable();
//item.ExtractValues(values);
string strTxt = item["Id"].Text; --> tthis return  
//if (values["Id"].ToString() == " " || string.IsNullOrEmpty(values["Id"].ToString()))
//{
// LogConfig.SaveInFile(Level.Debug, "Item does not exist in db", null, "ListMask.ascx.cs", "ItemCommand");
// string valueKey = values["Value"].ToString();
// listValues.Remove(listValues.Find(x => x.Value ==valueKey));
//}else
//{
// listValuesId.Add(Convert.ToInt32(values["Id"].ToString()));
// listValues.Remove(listValues.Find(x => x.Id == Convert.ToInt32(values["Id"].ToString())));
//}
}
new smListValues().DeleteValues(listValuesId, Convert.ToInt64(Session["ListId"]));
Session["Data"] = listValues;
MyGrid.Rebind();
break;
}
What I do wrong??