Calculate value inside gridview and update table

12 posts, 0 answers
  1. shivesh
    shivesh avatar
    38 posts
    Member since:
    Sep 2010

    Posted 27 Oct 2010 Link to this post

    Hi,

    I am using a gridview in this grid-view when user select item then rate column display rate. and user make input of quantity.
    not i want to column amount make calculation of rate and quantity column at the same time when user input amount.
    plz give me a sample example.

    whtever i did is...
    <telerik:RadGrid ID="radGrid1" runat="server" AutoGenerateColumns="False" GridLines="None"
            AllowMultiRowEdit="True" OnItemDataBound="radGrid1_ItemDataBound" OnNeedDataSource="radGrid1_NeedDataSource">
            <MasterTableView AutoGenerateColumns="false" EditMode="InPlace" ShowFooter="false" CommandItemDisplay="Top"  OnPreRender="radGrid1_PreRender">
                <Columns>
                    <telerik:GridTemplateColumn HeaderText="Product Name" UniqueName="Product_Name">
                        <ItemTemplate>
                            <asp:DropDownList ID="ddl1" runat="server" AutoPostBack="true" DataTextField="product_Name"
                                DataValueField="product_Name" OnSelectedIndexChanged="ddl1_SelectedIndexChanged">
                            </asp:DropDownList>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="Product_rate">
                        <ItemTemplate>
                            <asp:Label ID="lblrate" runat="server"></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="Product Quantity">
                        <EditItemTemplate>
                            <asp:TextBox ID="txtQuantity" runat="server" />
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="Product Amount">
                        <ItemTemplate>
                            <asp:Label ID="lblAmount" runat="server" />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
    protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
            {
                DropDownList list = (DropDownList)sender;
                GridDataItem item = (GridDataItem)list.NamingContainer;
              
                //display selected value of dropdown list.
     
                //string str = list.SelectedValue;
                //(item.FindControl("lblRate") as Label).Text = str;
                 
                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["chalk_hillConnectionString"].ConnectionString);
                con.Open();
                SqlCommand cmd = new SqlCommand("select product_rate from product_detail where product_name='" + list.SelectedItem.Text + "'", con);
                SqlDataReader reader; ;
                reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    (item.FindControl("lblRate") as Label).Text = reader["product_rate"].ToString();
                }
                 
            }
     
    protected void radGrid1_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem item = (GridDataItem)e.Item;
                    DropDownList list = (DropDownList)item.FindControl("ddl1");
                    list.Items.Insert(0, new ListItem("select", "-1"));
                    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["chalk_hillConnectionString"].ConnectionString);
                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = new SqlCommand("select product_name from product_detail", con);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    list.DataSource = ds;
                    list.DataBind();
                    
                }
     
            }

    with the above code i am able to display item from dropdown rate on selection of dropdownlist from database file.
    now want to update order table when user input quantity.

    Thanks
  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 29 Oct 2010 Link to this post

    Hello shivesh,

    Check the attached sample and let me know it this works for you.

    All the best,
    Iana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. shivesh
    shivesh avatar
    38 posts
    Member since:
    Sep 2010

    Posted 03 Nov 2010 Link to this post

    hi,
    Iana thanks for that it is working but when i am using RadNumerictextbox then OnTextChanged="txtQuantity_TextChanged" is not working may i know the reason???

    Thanks

    <telerik:RadGrid ShowFooter="true" ID="radGrid1" runat="server" OnInsertCommand="radGrid1_InsertCommand"
               AutoGenerateColumns="False" GridLines="None" AllowMultiRowEdit="True" AllowAutomaticInserts="true" OnItemInserted="radGrid1_ItemInserted"
               OnItemDataBound="radGrid1_ItemDataBound" OnNeedDataSource="radGrid1_NeedDataSource">
               <MasterTableView EditMode="InPlace" PageSize="5">
                   <Columns>
                       <telerik:GridTemplateColumn UniqueName="Product_Name" ReadOnly="true" HeaderText="Product Name">
                           <ItemTemplate>
                               <asp:DropDownList ID="ddl1" runat="server" AutoPostBack="true" DataTextField="product_Name"
                                   DataValueField="product_Name" OnSelectedIndexChanged="ddl1_SelectedIndexChanged">
                               </asp:DropDownList>
                           </ItemTemplate>
                       </telerik:GridTemplateColumn>
                       <telerik:GridTemplateColumn UniqueName="Product_Rate" ReadOnly="true" HeaderText="Product Rate">
                           <ItemTemplate>
                               <asp:Label ID="lblRate" runat="server" Text='<%#Eval("Product_Rate") %>'></asp:Label>
                           </ItemTemplate>
                       </telerik:GridTemplateColumn>
                       <telerik:GridTemplateColumn UniqueName="Product_Quantity" HeaderText="Product Quantity">
                           <ItemTemplate>
                               <telerik:RadNumericTextBox ID="txtQuantity" runat="server" OnTextChanged="txtQuantity_TextChanged">
                               </telerik:RadNumericTextBox>
                           </ItemTemplate>
                       </telerik:GridTemplateColumn>
                       <telerik:GridTemplateColumn UniqueName="Product_Amount" ReadOnly="true" HeaderText="Product Amount">
                           <ItemTemplate>
                               <asp:Label ID="lblAmount" runat="server"></asp:Label>
                           </ItemTemplate>
                       </telerik:GridTemplateColumn>
                   </Columns>
               </MasterTableView>
           </telerik:RadGrid>
    protected void txtQuantity_TextChanged(object sender, EventArgs e)
         {
            RadNumericTextBox textQuantity = sender as RadNumericTextBox;
             GridEditableItem item = textQuantity.NamingContainer as GridEditableItem;
             Label lbl1 = item["Product_Rate"].FindControl("lblRate") as Label;
             Label lbl3 = item["Product_Amount"].FindControl("lblAmount") as Label;
             lbl3.Text = (int.Parse(lbl1.Text) * int.Parse(textQuantity.Text)).ToString();
     
         }

    plz let me thanks
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Nov 2010 Link to this post

    Hello Shivesh,

    Set AutoPostBack ="'True"  to fire the OnTextChanged event of RadNumericTextBox .

    ASPX:
    <telerik:RadNumericTextBox ID="txtQuantity" runat="server" OnTextChanged="txtQuantity_TextChanged"
     AutoPostBack="True">
    </telerik:RadNumericTextBox>


    Thanks,
    Princy.
  6. shivesh
    shivesh avatar
    38 posts
    Member since:
    Sep 2010

    Posted 03 Nov 2010 Link to this post

    Thanks Princy
    it is working.
    I have one more query.
    how can i create new row for that. and here i am not saving value to database directly.
    i want to save all data in database after all input by user if user want to make 3 items then three
    row should be generate one by one. and at last click on submit button that are outside from grid .
    all data save in database table.

    i am using a session variable for saving all these thing plz guide me.
    thanks
  7. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 09 Nov 2010 Link to this post

    Hi shivesh,

    Indeed, if you want the user to insert more than one record, you need to save the already entered data into Session, ViewState or Cache. Could you please elaborate a bit on what are the exact issues you are facing while implementing this scenario?

    Kind regards,
    Iana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. shivesh
    shivesh avatar
    38 posts
    Member since:
    Sep 2010

    Posted 09 Nov 2010 Link to this post

    Hi,
    Can U give me any sample code program for saving value in session or viewstate after that on final submit button all session data save to database.

    Thanks
  9. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 15 Nov 2010 Link to this post

    Hello shivesh,

    Can you elaborate on the exact issues you are facing when trying to implement the suggested approach? Are you able to get the data from the grid? Or you have problems working with Session/ViewState and database?

    All the best,
    Iana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. shivesh
    shivesh avatar
    38 posts
    Member since:
    Sep 2010

    Posted 15 Nov 2010 Link to this post

    Hi Iana,
    I am able to retrieve data in grid from database but now challenge for me is that i want to hold some value of grid in session temporarily
    untill user make all entry after that when click on submit button all value shold be save in database there are order table pik only order number
    and order details table pick all value that inserted by user.
    I am unable to save data in session and again session to database how it will happen?
    Thanks
  11. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 18 Nov 2010 Link to this post

    Hi shivesh,

    Please find the answer provided in the other forum thread you have posted on this subject.

    Best wishes,
    Iana
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  12. Christophe
    Christophe avatar
    12 posts
    Member since:
    May 2015

    Posted 26 May 2015 in reply to Iana Tsolova Link to this post

    Hello,

    I tried your example but it did not work for me.

    How can I adapt it for when using EditFormSettings?

  13. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 29 May 2015 Link to this post

    Hello Christophe,

    As this thread is rather old and various issues had been discussed in it, it will be best to open a new forum thread and describes the exact requirements you have so that we can revise them locally and provide the best solution for your specific case.

    Regards,
    Maria Ilieva
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017