Mar 10, 2012, 5:12 AM
How to Get only Particular value from a grid panel on selected Row
I have my grid panel as follows

This is my code to delete the selected row but this is looping for row value as i used dictionary
<ext:GridPanel ID="GridPanel1" runat="server" Height="300" Title="Title">
<ColumnModel runat="server">
<Columns>
</Columns>
</ColumnModel>
<Store>
<ext:Store ID="Store1" runat="server" EnableViewState="true">
</ext:Store>
</Store>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" SingleSelect="true" runat="server">
</ext:RowSelectionModel>
</SelectionModel>
<Buttons>
<ext:Button ID="btnDelete" runat="server" Text="Delete">
<DirectEvents>
<Click OnEvent="Delete">
<ExtraParams>
<ext:Parameter Name="Values" Value="Ext.encode(#{GridPanel1}.getRowsValues({selectedOnly:true}))"
Mode="Raw" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
</Buttons>
</ext:GridPanel>
This is my grid from my databaseThis is my code to delete the selected row but this is looping for row value as i used dictionary
protected void Delete(object sender, DirectEventArgs e)
{
string json = e.ExtraParams["Values"];
string value = string.Empty;
Dictionary<string, string>[] companies = JSON.Deserialize<Dictionary<string, string>[]>(json);
bool addHeader = true;
foreach (Dictionary<string, string> row in companies)
{
if (addHeader)
{
//sb.Append("<tr>");
foreach (KeyValuePair<string, string> keyValuePair in row)
{
value = keyValuePair.Value.ToString();
SqlConnection con = new SqlConnection(connection);
con.Open();
SqlCommand cmd = new SqlCommand("Delete from Users where Name='" + value + "'", con);
cmd.ExecuteNonQuery();
BindData();
}
addHeader = false;
}
}
}
If I select first row and click on delete I would like to delete that row and Bind grid again. Can any one tell how to do this. Also I would like to alert a message box if the user didn't select any row using Java script
Last edited by Dorababu; Mar 10, 2012 at 6:12 AM.