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

Calculate value inside gridview and update table

11 Answers 324 Views
Grid
This is a migrated thread and some comments may be shown as answers.
shivesh
Top achievements
Rank 1
shivesh asked on 27 Oct 2010, 12:31 PM
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

11 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 29 Oct 2010, 03:01 PM
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
0
shivesh
Top achievements
Rank 1
answered on 03 Nov 2010, 11:16 AM
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
0
Princy
Top achievements
Rank 2
answered on 03 Nov 2010, 01:16 PM
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.
0
shivesh
Top achievements
Rank 1
answered on 03 Nov 2010, 01:22 PM
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
0
Iana Tsolova
Telerik team
answered on 09 Nov 2010, 11:17 AM
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
0
shivesh
Top achievements
Rank 1
answered on 10 Nov 2010, 05:29 AM
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
0
Iana Tsolova
Telerik team
answered on 15 Nov 2010, 10:28 AM
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
0
shivesh
Top achievements
Rank 1
answered on 15 Nov 2010, 12:30 PM
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
0
Iana Tsolova
Telerik team
answered on 18 Nov 2010, 12:15 PM
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.
0
Christophe
Top achievements
Rank 1
answered on 27 May 2015, 12:56 AM

Hello,

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

How can I adapt it for when using EditFormSettings?

0
Maria Ilieva
Telerik team
answered on 29 May 2015, 08:44 AM
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
Tags
Grid
Asked by
shivesh
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
shivesh
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Christophe
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or