RadButton Quest!!

2 posts, 0 answers
  1. Francisco
    Francisco avatar
    1 posts
    Member since:
    Sep 2013

    Posted 26 Sep 2013 Link to this post

    I am new in the asp.net code and i need generate a report in a gridview with objectdatasource,  when i click a button and the parameters of 4 textbox add to query
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 27 Sep 2013 Link to this post

    Hi Francisco,

    Please have a look into the full code that I tried to populate RadGrid using ObjectDataSource.

    ASPX:
    <telerik:RadTextBox ID="RadTextBox1" runat="server">
    </telerik:RadTextBox>
    <telerik:RadButton ID="RadButton1" runat="server" Text="Generate Gird" OnClick="RadButton1_Click">
    </telerik:RadButton>
    <telerik:RadGrid ID="RadGrid1" AllowPaging="true" AllowSorting="true" runat="server"
        AllowFilteringByColumn="true" Width="100%">
        <PagerStyle AlwaysVisible="true"></PagerStyle>
    </telerik:RadGrid>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="Class1" OnSelecting="ObjectDataSource1_Selecting">
        <SelectParameters>
            <asp:Parameter Name="textvalue" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>

    C#:
    protected void RadButton1_Click(object sender, EventArgs e)
    {
        RadGrid1.DataSourceID = "ObjectDataSource1";
        ObjectDataSource1.SelectMethod = "GetData";
    }
     
    protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
    {
        //passing the parameter value from code
        e.InputParameters["textvalue"] = RadTextBox1.Text;
    }
     
    Code inside App_Code:
    public class Class1
    {
        public DataTable GetData(string textvalue)
        {
            String connectionstring = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
            SqlConnection sqlconn = new SqlConnection(connectionstring);
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = new SqlCommand("SELECT text from Details WHERE id LIKE '" + textvalue + "%'", sqlconn);
            DataTable data = new DataTable();
            sqlconn.Open();
            try
            {
                adapter.Fill(data);
                return data;
            }
            finally
            {
                sqlconn.Close();
            }
        }
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top