This is a migrated thread and some comments may be shown as answers.

radgrid selected values

5 Answers 347 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Troika
Top achievements
Rank 1
Troika asked on 22 Oct 2013, 10:50 AM
i'm binding a radgrid with custom dataset that i cal on need datasourece event

but then i need to fetch the username of select row on grid , but it gices always null:

string username = (string)RadGrid1.SelectedValues["UserName"];


i think its because i'm databing on code behind because with sql datasource directly associated with grid works fine

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 Oct 2013, 12:19 PM
Hi Troika,

Please try the following code snippet ,I have tried to access the selected rows on a button click.

ASPX:
<rad:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" AllowMultiRowSelection="true">
    <MasterTableView >   
        <Columns>
            <rad:GridBoundColumn DataField="CustomerID" UniqueName="CustomerID">
            </rad:GridBoundColumn>
            <rad:GridBoundColumn DataField="CompanyName" UniqueName="CompanyName">
            </rad:GridBoundColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings Selecting-AllowRowSelect="true" >
    </ClientSettings>
</rad:RadGrid>

C#:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        String ConnString = ConfigurationManager.ConnectionStrings["Northwind_newConnectionString3"].ConnectionString;
        SqlConnection conn = new SqlConnection(ConnString);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand("SELECT CustomerID, CompanyName FROM Customers", conn);
 
        DataTable myDataTable = new DataTable();
 
        conn.Open();
        try
        {
            adapter.Fill(myDataTable);
        }
        finally
        {
            conn.Close();
        }
 
        RadGrid1.DataSource = myDataTable;
    }
 
 protected void Button1_Click(object sender, EventArgs e)
    {      
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
        {
            if (item.Selected == true)
            {
                string mydata = item["CustomerID"].Text;
            }
        }
    }

Thanks,
Princy
0
Troika
Top achievements
Rank 1
answered on 22 Oct 2013, 01:34 PM
that dont work because i dont select the row i just click on the row
0
Troika
Top achievements
Rank 1
answered on 22 Oct 2013, 02:22 PM
i'm using 

<telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" Text="Apagar" UniqueName="DeleteColumn">

 

 

 

then on item command

if (e.CommandName == "Delete") but i cant get the username of the custom dataset bind on need datasource event

0
Princy
Top achievements
Rank 2
answered on 23 Oct 2013, 04:59 AM
Hi Troika,

I have bind the radgrid in the NeedDataSource event as shown in the above code,In order to access the selected row on the button click,please try the following code snippet.

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
 if (e.CommandName == "Delete")
 {
  GridDataItem data = (GridDataItem)e.Item;
  string mydata = data["CustomerID"].Text;
 }
}

Thanks,
Princy
0
Troika
Top achievements
Rank 1
answered on 27 Oct 2013, 10:25 PM
this works.

Help me on this please i cant fix it
Tags
Grid
Asked by
Troika
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Troika
Top achievements
Rank 1
Share this question
or