Forms Data Controls :: Gridview-Calculate Value Based On Formula That Varies Dependent On Selected Code In Dropdownlist?

Jul 2, 2010

GridViewDetails uses templatefields. In edittemplate I put a button called "ButtonUpdateAdjustAmount" with OnClick="Update_AdjustAmount" in the EditItemTemplate for the "Amt to be Adj" column. There is also a textbox. My user's should be able to edit the textbox, but I also want the ability to click the button and the textbox populated with the correct calculated value. The formula varies based on the "code" column which is a dropdownlist called "DropListCode".

I am fairly new to asp.net, vb, etc...so forgive my code writing. Eventually I need to also put the same functionality on the insertrow for my gridview. But first wanted to get the edit one working. I am using templatefields for all columns and the FooterTemplate to perform the Insert New Detail Line.

I can get the functionality to work for the first data row and only if I take out the If code.SelectedValue = ... line and leave 1 static formula. However that isn't going to work. If DropListCode.SelectedValue is DNR then AdjAmt should be ((q_ordered - q_received) * cost). If DropListCode. SelectedValue is OV then AdjAmt should be (RKNumber * cost). If DropListCode.SelectedValue is NB the AdjAmt should be ((q_received - q_ordered) * cost). If DropListCode.SelectedValue is DAM then AdjAmt should be (RKNumber * cost)

Code behind for the OnClick:

[Code]....

.aspx page - GridViewDetails programming:

[Code]....

View 6 Replies


Similar Messages:

Data Controls :: Change Background Color Of GridView Cell Based On DropDownList Selected Value

Feb 15, 2014

I have a grid with 5 rows and 5 columns, All containing templetefield(Combobox)I am trying to set the background color of my grid cell(contain combobox) depending upon which item is selected. (again, dependent on item selection, so background color is not permanent). How can i achieve this?

View 1 Replies

Data Controls :: Enable / Disable TextBox Based On Selected Value Of DropDownList Inside GridView

May 7, 2015

I'm using a gridview rows, in that I'm adding the rows. I need to disable the textboxes based upon the selected value from the dropdownlist (Yes / No). This should be remain same for the previous rows when ever I'm adding new rows.

View 1 Replies

Data Controls :: Show / Hide TextBox Based On Selected Value Of DropDownList Inside GridView

May 7, 2015

In my query i have 1 gridview..

In this gridview i have 1 dropdownlist and  1 textbox..

textbox is in visible=false state..

My question is after selecting dropdown list selected value i want visible textbox in gridview..

View 1 Replies

Data Controls :: Implement Dependent Cascading DropDownList In GridView TemplateField

Dec 23, 2013

How do I fill ProductNameID on selection of ProductCategoryID dropdown by passing

ProductCategoryID .SelectedValue...

aspx Code

<asp:GridView ID="gridPosition" runat="server" AutoGenerateColumns="False" ShowFooter="True" OnRowDataBound="gridPosition_onRowDataBound"
DataKeyNames="SaleDetailID" OnRowEditing="gridPosition_RowEditing"
OnRowCancelingEdit="gridPosition_RowCancelingEdit" OnRowUpdating="gridPosition_RowUpdating"
OnRowDeleting="gridPosition_RowDeleting" ShowHeaderWhenEmpty="True" CssClass="manage-admin"
Width="500px" GridLines="None">

[Code] .....

View 1 Replies

Forms Data Controls :: GridView,calculate Value Based On Other Columns& Save To Datasource?

Nov 8, 2010

I had just started with Visual Studio 2008 + VB.net. I've now designed my tables, and basic gridview functions properly.Now I'm faced with the problem of having to calculate a value based on 2 - 3 columns/data in the gridview, display the result in an existing column in the same gridview, and saving the calculated value in the datasource.I had initially created the "Total" column as a textbox displaying a manually calculated amount that is saved in the datasource. Now, I want to change the field to auto-calculate based on 2 other columns.

View 4 Replies

Forms Data Controls :: GridView - Calculate Date And Time In DropDownList?

Oct 5, 2010

How to calculate date and time in DropDownList?

View 2 Replies

Disabling Dropdownlist Inside A Gridview Based On Value Selected On Another Dropdownlist?

Jan 11, 2011

what i m trying is i hav two dropdownlists inside the gridview... namely say ddonsiteoffsite and ddhours... now what i want is if the selectedtext of ddonsiteoffsite is "onsite" the ddhours should b disabled... i tried the code snippet but ... its not disabling the ddhours... can someone help me please..

<asp:TemplateColumn HeaderText=" OnSite/OffSite" >
<ItemTemplate>
<asp:DropDownList ID="ddOnsiteOffside" runat="server" onchange="ToggleOnOff(this)">
[code].....

View 2 Replies

Forms Data Controls :: Make Panel Control Visible Based On Selected Value In A DropDownList Box?

May 17, 2010

I have a Data Bound DropDownList and a Panel in a step of the CreateUserWizard. I would like to make the panel visible based on the selected value of the DropDownList.

Here is my code that is not working. Any help identifying what I missed is appreciated. (Yes Post Back is enabled on the DropDownList.

[Code]....

View 3 Replies

Data Controls :: Set RadioButtonList Selected Value Based On GridView Selected Row?

May 7, 2015

how to display GridView Selected Row in dropdownlist and radiobutton outside GridView in ASP.Net?

View 1 Replies

Data Controls :: Change And Update TextBox Value Based On DropDownList Selected Value

Jun 16, 2015

I have one dropdown list and two textbox. I am developing a small application for my par tics in which currency name  populate from the data base which are in drop down it will working now.

Now I want when I select currency name from dropdown list the code the and the country name show in the  other textbox value .for example when I select Currency name like UK pound the value show .one show currency code 2 and other country name United state. All text box  value change on changing vale in droupdownlist dynamically means all value dependent on the dropdown list .

All value from the data base  

I  bind three value with the currency name ,id,currency code and country name. because when I change the dropdown list so change value in text box .but I fail to do that.

How to value change in textbox to changing value in dropdown list. I know code show be on the DropDownList1_SelectedIndexChanged but I have no exact code

My data base.table

Id (primary key)Currency NameCurreny codecountyname
1 Bangla Taka3 Bangldash
2 Chines Yan5China

Code
private String strConnection = "Data Source=.SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|Database1.mdf;User Instance=true";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)

[Code] .....

View 1 Replies

Forms Data Controls :: Filter Gridview Based On Value From Dropdownlist?

Aug 9, 2010

I have a gridview that I'd like to have changed based on a value selected in a dropdownlist. I'm able to get the aspx page to display the dropdown list (comming from SQL), and when I select a value, the page reloads, but no data show in the griview.

[Code]....

Here is the aspx page:

[Code]....

View 8 Replies

Forms Data Controls :: Getting Dropdownlist Selected Value From The Gridview?

Jun 29, 2010

i want to get the selected value from the dropdown from the gridview

how do i do this i have tried a lot but fail :(

View 17 Replies

Forms Data Controls :: Gridview - Insert Multiple Rows Based On Selected Checkbox

Aug 11, 2010

I have a gridview object to which I added

<asp:TemplateField >
<ItemTemplate>
<asp:CheckBox ID="chkCopy"
OnCheckedChanged="chkStatus_OnCheckedChanged"
runat="server" />
</ItemTemplate>
</asp:TemplateField>

The page count is set to 10, when the user checks the checkbox(es), I will need to insert those records in a table. How will I know which row was selected? I found an example (untried) that is designed to loop through and insert the necessary records; but it does not address inserting records based on selecting rows via a checkbox. How do I put everything together.

// open connection
mySqlConnection.Open();
//enumerate the items in the list
foreach (SPListItem curItem in curItems)
{
string sql = "INSERT INTO ImportNotifications";
sql += "
(SharepointID,Title,WorkOrderNumber,Status,Department,ClientName,WorkOrderDueDate,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,Late,LateRe
view,TrueLate,Body)";
sql += " VALUES
(@ID,@Title,@WorkOrderNum,@Status,@Department,@ClientName,@WorkOrderDue,@Created,@Author,@Modified,@Editor,@Late,@LateReview,@TrueLate,@Bod
y)";
mySqlCommand.CommandText = sql;
mySqlCommand.Parameters.Clear();
mySqlCommand.Parameters.Add(new SqlParameter("@ID", SqlDbType.Float)).Value = curItem["ID"];
mySqlCommand.Parameters.Add(new SqlParameter("@Title", SqlDbType.NVarChar, 200)).Value =
curItem["Title"].ToString();
mySqlCommand.Parameters.Add(new SqlParameter("@WorkOrderNum", SqlDbType.NVarChar, 50)).Value =
curItem["Work_x0020_Order_x0020_Number"].ToString();
mySqlCommand.Parameters.Add(new SqlParameter("@Status", SqlDbType.NVarChar, 50)).Value =
curItem["Status"].ToString();
mySqlCommand.Parameters.Add(new SqlParameter("@Department", SqlDbType.NVarChar, 100)).Value =
curItem["Department"].ToString();
mySqlCommand.Parameters.Add(new SqlParameter("@ClientName", SqlDbType.NVarChar, 255)).Value =
curItem["Client_x0020_Name"].ToString();
mySqlCommand.Parameters.Add(new SqlParameter("@WorkOrderDue", SqlDbType.DateTime)).Value =
curItem["Work_x0020_Order_x0020_Due_x0020"];
mySqlCommand.Parameters.Add(new SqlParameter("@Created", SqlDbType.DateTime)).Value = curItem["Created"];
mySqlCommand.Parameters.Add(new SqlParameter("@Author", SqlDbType.NVarChar, 50)).Value =
curItem["Author"].ToString();
mySqlCommand.Parameters.Add(new SqlParameter("@Modified", SqlDbType.DateTime)).Value = curItem["Modified"];
mySqlCommand.Parameters.Add(new SqlParameter("@Editor", SqlDbType.NVarChar, 50)).Value = curItem["Editor"];
mySqlCommand.Parameters.Add(new SqlParameter("@Late", SqlDbType.NVarChar, 50)).Value = curItem["Late"];
mySqlCommand.Parameters.Add(new SqlParameter("@LateReview", SqlDbType.NVarChar, 50)).Value =
curItem["Late_x0020_Review"];
mySqlCommand.Parameters.Add(new SqlParameter("@TrueLate", SqlDbType.NVarChar, 50)).Value = curItem["TrueLate"];
mySqlCommand.Parameters.Add(new SqlParameter("@Body", SqlDbType.NVarChar, -1)).Value =
curItem["Body"].ToString();
// execute the command
mySqlCommand.ExecuteNonQuery();
}
// close the connection
mySqlConnection.Close();

View 4 Replies

Forms Data Controls :: Selected Value Not Retaining In Dropdownlist In Gridview?

Jan 19, 2010

I have a Grid on my page.When the page is loaded for the first time ther is a list of records displayed in the grid.When I edit the record by edit link button,the ddl saves the change value .

The same thing if I do when searching for a particular record and then editing and changeing the dropdownlist value,the page postbacks and the new value gets replaced with the old value that was present earlier.

View 15 Replies

Forms Data Controls :: Losing Selected Value From A Dropdownlist In Gridview?

Jan 11, 2011

I have the following gridview...

[Code]....

And inside that gridview you can see I have a dropdownlist called dpdTrueFalse. That dropdown has two values which I am loading from code behind like this...

[Code]....

I have a submit button outside that gridview that checks each row and the selected value in the dropdown. But for some reason, even if you select another item in the dropdown, it always selects the first item in the dropdown when I click the submit button. I reckon its because of the postback.

View 5 Replies

Forms Data Controls :: Displaying Selected Value Fom DropDownList In GridView?

Apr 28, 2010

I want to display a GridView using the the selected DataValueField from the DropdownList.

I've set the Selectparameters for the GridView DataSource.

Here is my question: on clicking "BtnSelect" - How do I assign this parameter (@Id) to selected value (DataValueField) from the DropDownList and re-display the grid view accordingly?

Here is what I got so far:

[Code]....

View 5 Replies

Forms Data Controls :: How To Display The Data Based On Dropdownlist Value In Gridview

Dec 30, 2010

I have a gridview.In Header of gridview i added dropdownlist.

[Code]....

Here the problem is, i am getting selected value in temp variable(if i change to 20,50,100) in dropdown selection event but it is not binding the pagesize for the gridview and also dropdownlist showing the value "10" only after the pageload.

View 6 Replies

Data Controls :: Populate GridView Based On Selected Row Of Another GridView?

May 7, 2015

how to display data in a gridview2 which is depends from the selected row in gridview1?

View 1 Replies

Forms Data Controls :: Showing A Selected Value Of Dropdownlist In The Header Template Of A Gridview?

May 17, 2010

How to display the selected value of a dropdownlist in header taemplate of a gridview? As i change the dropdownlist's value, it should also change in the gridview. i have taken a label in the gridview's header template named "lbl_mnth" my dropdownlist's id is "ddl_mnth".

View 1 Replies

Forms Data Controls :: Maintaining Selected Values In DropDownList While Paging In GridView

Jan 8, 2011

I have a problem with keeping the selected values in DropDownLists in rows in GridView while paging. I have this code behind:

private void RememberOldValues()
{
ArrayList LinijaIDList = new ArrayList();
int index = -1;
foreach (GridViewRow row in GridView1.Rows)
{
index = (int)GridView1.DataKeys[row.RowIndex].Value;
if (Session["equal_ITEMS"] != null)
LinijaIDList = (ArrayList)Session["equal_ITEMS"];
if (row.Cells[0].Text == lineTextBox.Text)
{
if (!LinijaIDList.Contains(index))
LinijaIDList.Add(index);
}
else
LinijaIDList.Remove(index);
}
if (LinijaIDList != null && LinijaIDList.Count > 0)
Session["equal_ITEMS"] = LinijaIDList;
}
protected void Button1_Click(object sender, EventArgs e)
{
//Session["equal_ITEMS"] = null;
RememberOldValues();
GridView1.AllowPaging = false;
BindGrid();
//RePopulateValues();
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("LinijaID", typeof(int)));
dt.Columns.Add(new DataColumn("Ime", typeof(string)));
ArrayList LinijaIDList = (ArrayList)Session["equal_ITEMS"];
//if (LinijaIDList!=null)
//{
foreach (int LinijaID in LinijaIDList)
{
foreach (GridViewRow row in GridView1.Rows)
{
DropDownList Ime = GridView1.FooterRow.FindControl("ImeDropDownList") as DropDownList;
int rowID = (int)GridView1.DataKeys[row.RowIndex].Value;
//string Name = row.Cells[1].Text;
string Name = Ime.SelectedValue;
if (rowID == LinijaID)
{
DataRow dr = dt.NewRow();
dr["LinijaID"] = LinijaID;
dr["Ime"] = Name;
dt.Rows.Add(dr);
}
}
}
GridView1.AllowPaging = true;
Session["equal1"] = dt;
Response.Redirect("CheckedRowsPage1.aspx");
}
// else
//{
// GridView1.AllowPaging = true;
// Session["equal1"]=null;
// }
}

When I insert a value in the TextBox2 and want to select only the rows from the GridView from different pages which have value in the first column the same as the value in the TextBox2, after clicking on Button1 I get this error:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

[Code]....

View 3 Replies

Forms Data Controls :: Dynamic Gridview With Dropdownlist / Dynamically Set The List Values Based On Parameters (of The Row They Are On)

May 28, 2010

I'm new to web dev and c# so please bare with me. I am trying to create a dynamic gridview in a web form for users to to answer questions with (code below).

The dificulty im having is that i am nesting a dropdwonlist in the gridview and want to be able to dynamically set the list values based on parameters (of the row they are on). These values are in the main dataset for the gridview as each row represents a questionid and question text and then a ddl for the criteria...

I just don't know how to set the values for the dropdown all the code so far is below... just need to be able to populate the dropdowns with the relevant values.

I have created a stored proc to return the different criteria based on the questionid and questionGroupid which is the dataset that populates the other fields in the gridview: dbo.usp_QuestionCriteria @QuestionGroupId, @QuestionId

I have added this as a tableadapter called criteriaTableAdapter in a xsd file as well using the wizard... not sure if this is the right option though or just use the same method as i have for the other stored procedure as in the code below:

[CODE

]using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Sql"].ConnectionString);
con.Open();
SqlCommand com = new SqlCommand("usp_QuestionGroupDS", con);
com.CommandType = CommandType.StoredProcedure;
SqlDataAdapter ada = new SqlDataAdapter(com);
DataSet ds = new DataSet();
ada.Fill(ds);
for (int i = 0; i < ds.Tables.Count; i++)
{
if (ds.Tables[i].Rows.Count > 0)
{
GridView gvDynamicQuestion = new GridView();
gvDynamicQuestion.Width = Unit.Pixel(700);
gvDynamicQuestion.BorderWidth = Unit.Pixel(0);
gvDynamicQuestion.Caption = "<div id="nifty" class="QuestionGroup"> <b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>" + ds.Tables[i].Rows[0]["Category"].ToString() + " Questions<b class="rbottom"><b
class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b></div>";
gvDynamicQuestion.AutoGenerateColumns = false;
gvDynamicQuestion.ShowFooter = true;
TemplateField tf = null;
tf = new TemplateField();
tf.HeaderTemplate = new DynamicGridViewTextTemplate("QuestionId", DataControlRowType.Header);
tf.ItemTemplate = new DynamicGridViewTextTemplate("QuestionId", DataControlRowType.DataRow);
tf.FooterTemplate = new DynamicGridViewTextTemplate(DataControlRowType.Footer, ds.Tables[i].Rows.Count);
gvDynamicQuestion.Columns.Add(tf);
tf = new TemplateField();
tf.HeaderTemplate = new DynamicGridViewTextTemplate("Question", DataControlRowType.Header);
tf.ItemTemplate = new DynamicGridViewTextTemplate("Question", DataControlRowType.DataRow);
gvDynamicQuestion.Columns.Add(tf);
tf = new TemplateField();
tf.HeaderText = "Criteria";
tf.HeaderTemplate = new DynamicGridViewTextTemplate("Criteria", DataControlRowType.Header);
tf.ItemTemplate = new DynamicGridViewDDLTemplate();
gvDynamicQuestion.Columns.Add(tf);
////tf = new TemplateField();
////tf.HeaderText = "Criteria";
////tf.ItemTemplate = new DynamicGridViewDDLTemplate();
////gvDynamicQuestion.Columns.Add(tf);
gvDynamicQuestion.DataSource = ds.Tables[i];
gvDynamicQuestion.DataBind();
phDynamicGridHolder.Controls.Add(gvDynamicQuestion);
}
}
}
protected void DynamicGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
//
}
}
}
public class DynamicGridViewTextTemplate : ITemplate
{
string _ColName;
DataControlRowType _rowType;
int _Count;
public DynamicGridViewTextTemplate(string ColName, DataControlRowType RowType)
{
_ColName = ColName;
_rowType = RowType;
}
public DynamicGridViewTextTemplate(DataControlRowType RowType, int QuestionCount)
{
_rowType = RowType;
_Count = QuestionCount;
}
public void InstantiateIn(System.Web.UI.Control container)
{
switch (_rowType)
{
case DataControlRowType.Header:
Literal lc = new Literal();
lc.Text = "<b>" + _ColName + "</b>";
container.Controls.Add(lc);
break;
case DataControlRowType.DataRow:
Label lbl = new Label();
lbl.DataBinding += new EventHandler(this.lbl_DataBind);
container.Controls.Add(lbl);
break;
case DataControlRowType.Footer:
Literal flc = new Literal();
flc.Text = "<b>Total No of Questions:" + _Count + "</b>";
container.Controls.Add(flc);
break;
default:
break;
}
}
private void lbl_DataBind(Object sender, EventArgs e)
{
Label lbl = (Label)sender;
GridViewRow row = (GridViewRow)lbl.NamingContainer;
lbl.Text =DataBinder.Eval(row.DataItem, _ColName).ToString();
}
}
public class DynamicGridViewDDLTemplate : ITemplate
{
// Implementation of ITemplate
public void InstantiateIn(System.Web.UI.Control container)
{
// Create a DDL
DropDownList ddl = new DropDownList();
//Attach method to delegate
ddl.DataBinding += new System.EventHandler(this.ddl_DataBind);
container.Controls.Add(ddl);
}
//Method that responds to the DataBinding event
private void ddl_DataBind(object sender, System.EventArgs e)
{
//DropDownList ddl = (DropDownList)sender;
//DataGridItem container = (DataGridItem)ddl.NamingContainer;
//ddl.Data.Checked = [Data binding expression];
}
}

[/CODE]

View 7 Replies

Forms Data Controls :: Gridview Row Sometimes Has To Be Selected Twice For Code To Work

Oct 13, 2010

I'm using the code below to extract data from a gridview and populate it into textboxes for the days and two drop downs for Project and Category.

For some rows in the gridview everything but the category ddl populates correctly. If I click the row a second time the category ddl displays the correct category.

why I have to click twice for some rows? And how do I fix this?

[Code]....

View 1 Replies

Forms Data Controls :: Bind Value To Selected Value Of Dropdownlist In Gridview And Update By Stored Procedure?

Dec 9, 2010

Girdview has dropdownlist TemplateField called ddlSate, how to bind state field value in sql table to selected value of ddlState dropdownlist control? For example the sql table has AL value for state field, (Note by default ddlState lists all states options with sqldatasource), how AL is selected in ddlState when binding to ddlState?

Secondly, when user selects different state like GA, how below update stored precedure works? that means how to find ddl selected value in update procedure as shown below question mark line:

Here is part code:

<asp:GridView ID="gvOrder" runat="server" DataSourceID="ods1" AutoGenerateColumns="False"
style="margin-top: 11px" CssClass="pnlOrdercss" ScrollBars="Both"
BorderColor="Black" BorderWidth="1px">
<Columns>

[Code]....

View 2 Replies

C# - Disable Or Enable 2nd Dropdownlist In Aspx Based On Selected Choice Of The 1st Dropdownlist Box

Apr 15, 2010

I am having a problem with disabling DropDownList based on the chice of 1st DropDownList, there is no post back occuring, and it is a template based web app here is the current code:

<script type="text/javascript">
$(function() { var dropDownList1 = $('#<%= ddlUserType.ClientID %>');
var dropDownList2 = $('#<%= ddlMember.ClientID %>'); dropDownList1.change(function(e) {
if ( jQuery("#ddlUserType").val() != "ETOC") dropDownList2.removeAttr('disabled'); e.preventDefault();
else
dropDownList2.removeAttr('enabled'); e.preventDefault(); }
} );
</script>

what is happening now is page is blank and if I remove the above code everything shows, where I am going wrong. here is the plain and final javascript code which worked:

<script language="javascript">
function CheckDropDownState(lstbox)
{
if (lstbox.selectedIndex == 3) { document.forms[0].ddlMember.disabled = 1; }
else { document.forms[0].ddlMember.disabled = 0; }
}
</script>

and thew .aspx code: <asp:dropdownlist id="ddlUserType" runat="server" onclick="CheckDropDownState(this);"></asp:dropdownlist>

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved