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

RadButton Quest!!

1 Answer 23 Views
Button
This is a migrated thread and some comments may be shown as answers.
Francisco
Top achievements
Rank 1
Francisco asked on 26 Sep 2013, 03:23 PM
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

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 27 Sep 2013, 10:56 AM
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.
Tags
Button
Asked by
Francisco
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or