Here are my requirements:
- I have a drop-down list and a text box (application name and profile).
- I want to take values ββfrom a drop-down list and a text field and add them to a table (or a control like gridview that displays the table)
- At some point, I want to be able to scroll through a table and pass values ββto db.
My problem:
- Rollback caused by onClick parity parses the table to display only the last entered value and does not save any of the previous values.
Notes:
- I tried to work with this using a datalist tied to a datagrid, but no luck.
code:
protected void addAppButton_Click(object sender, EventArgs e) { DropDownList appList = (DropDownList)newEntryFV.FindControl("appList"); TextBox profileTextBox = (TextBox)newEntryFV.FindControl("profileTextBox"); addAppsToTable(appList.SelectedValue.ToString(), profileTextBox.Text.ToString()); } private void addAppsToTable(string appName, string profileName) { Table appsTable = (Table)newEntryFV.FindControl("appTable"); TableRow newRow = new TableRow(); TableCell appNameCell = new TableCell(); TableCell profileCell = new TableCell(); appNameCell.Text = appName; profileCell.Text = profileName; newRow.Cells.Add(appNameCell); newRow.Cells.Add(profileCell); appsTable.Rows.Add(newRow); }
Code that solved my problem:
[Serializable] public class securityApps { public string secAppID { get; set; } public string secAppName { get; set; } public string secProfile { get; set; } } protected void Page_Load(object sender, EventArgs e) { BindApps(); } protected void addAppButton_Click(object sender, EventArgs e) { DropDownList appList = (DropDownList)newEntryFV.FindControl("appList"); TextBox profileTextBox = (TextBox)newEntryFV.FindControl("profileTextBox"); addAppsToListVS(appList.SelectedValue.ToString(), appList.SelectedItem.Text.ToString(), profileTextBox.Text.ToString()); BindApps(); } private void addAppsToListVS(string appID, string appName, string profile) { securityApps secApp = new securityApps(); secApp.secAppID = appID; secApp.secAppName = appName; secApp.secProfile = profile; ((List<securityApps>)ViewState["appsListVS"]).Add(secApp); }
source share