简体   繁体   中英

How to Get only Particular value from a grid panel on selected Row

I have my grid panel as follows

<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 database

在此处输入图片说明

This 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

Is this ExtJs4? Look for getSelectionModel().getSelection() method of your grid control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM