How to get value from selected row of GridPanel? [Ext.Net]

3.2k views Asked by At

I wanna access value of first column of selected row. I used SqlDataSource as a source, and ModelFields in Store. I got datas for GridPanel directly from sql database. I am accessing row number of selected rows by using ;

  RowSelectionModel rsm = grid1.SelectionModel.Primary as RowSelectionModel;
  rsm.SelectedIndex.ToString();

and record id returns something that i did not implement;

  rsm.SelectedRecordID;     //returns ext-33-0 or ext-33-1 depends on row number

How can I access the first (or any) column of selected row? Thank you.

Related scripts;

  <asp:SqlDataSource 
        ID="SqlDataSource1" 
        runat="server" 
        ConnectionString="<%$ ConnectionStrings:Database %>"
        />
   <ext:Store ID="sqlStore" runat="server" DataSourceID="SqlDataSource1" >


    <Model>
        <ext:Model runat="server">
            <Fields>
                <ext:ModelField Name = "billNo" Unique="true" />
                <ext:ModelField Name = "senderVKN" />
                <ext:ModelField Name = "receiverVKN" />
                <ext:ModelField Name = "Date" Type="Date" />
                <ext:ModelField Name = "Amount" />
            </Fields>
        </ext:Model>
    </Model>
</ext:Store>


  <ext:GridPanel ID="grid1" runat="server"
                AnchorHorizontal="100%"
                AnchorVertical="20%"
                ColumnLines ="true" 
                StoreID ="sqlStore">
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column ID="billColumn" runat="server" Text="Bill No" DataIndex="billNo" ></ext:Column>
                        ...
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" Mode="Single" />
                </SelectionModel>
            </ext:GridPanel>
1

There are 1 answers

0
Gökhan Nas On BEST ANSWER

First of all I changed some parts of my code;

 <ext:Store ID="sqlStore1" runat="server" DataSourceID="SqlDataSource1" >
    <Model>
        <ext:Model IDProperty="RowID" runat="server" Name="storeModel" >
            <Fields>
                <ext:ModelField Name = "RowID" Type="String"/>
                <ext:ModelField Name = "BillNo" Type="String"/>
                <ext:ModelField Name = "SenderVKN" />
                <ext:ModelField Name = "ReceiverVKN" />
                <ext:ModelField Name = "Date" Type="Date" />
                <ext:ModelField Name = "Amount" />
                <ext:ModelField Name = "Description" />
            </Fields>
        </ext:Model>
    </Model>
</ext:Store>

then I used RowSelectionModel;

 protected void appBillButton_DirectClick(object sender, DirectEventArgs e)
    {
        RowSelectionModel rsm = grid1.SelectionModel.Primary as RowSelectionModel;
        if (rsm.SelectedRows.Count > 0)
        {
            foreach (SelectedRow sr in rsm.SelectedRows)
            {
                //DoSomeFunction();
            }
            X.Msg.Info("Success", "Function completed successfuly.");
        }
        else
        {
            X.Msg.Alert("Error", "Please select row.").Show();
        }
}

Model field names must be same with your SqlDataSource's command value names.