-2

May I use the selected Value from the RadioButtonList in the IQueryable to get selected values from a table?

I have RadioButtonList with DataValueField="Code"

My code is

public IQueryable<Tbl_name> GetValuesfromTable()
{
    return dbo.Tbl_name.Where(q => q.Code = (RadioButtonList.SelectedItem.Value)).OrderBy(c => c.Date_publication);
}

Please can you help me with this query?

zx485
  • 28,498
  • 28
  • 50
  • 59
Peter
  • 1
  • 1

1 Answers1

0

If you want to get the single value from that table. I am considering that Code is being serialized as a int:

public IQueryable<Tbl_name> GetValuesfromTable()
{
    var selectedCode = Convert.ToInt32(RadioButtonList.SelectedValue);
    return dbo.Tbl_name.Where(q => q.Code == selectedCode)
        .OrderBy(c => c.Date_publication);
}
Akira Yamamoto
  • 4,685
  • 4
  • 42
  • 43
  • The error is .. "Cannot implicitly convert type 'string' to 'int' . However I have tried Convert.ToInt32(RadioButtonList.SelectedItem.Value) and does not work either... The radio bautton value in general it is a number .... I have tried return dbo.Tbl_name.Where(q=>q.Code== 1) which works... – Peter Dec 10 '15 at 14:16
  • Actually I would like to get a list of values ( GridView ) from that Table_name.. but only where Code is equal to the value from the RadiobuttonList... – Peter Dec 10 '15 at 14:21
  • Put the `Convert.ToInt32` outside of the LINQ query. See the updated answer. – Akira Yamamoto Dec 10 '15 at 14:29
  • 1
    Thank you a lot... it almost works.. with small correction that I added one more == so now it is (q => q.Code == selectedCode).... however in my case result of this query supposed to feel the GridView. when I insert a fixed number like (q => q.Code == 5 )etc.. so it will fill my gridview but the variable selectedCode does not.. My RadiobuttonList have AutoPostBack="true" ; My grid SelectMethod="GetValueFromTable" but something is still wrong.. I am trying to solve it still but I cannot .. Maybe I supposed to bind in some way the data from this function to the gridView SelectedIndexChanged? – Peter Dec 10 '15 at 17:59