I want to implement the following scenario...
Table related to this question is as follows:
ProfileID int (identity)
FirstName varchar(100)
LastName varchar(100)
step 1. User visits profiles.aspx page. Here in a grid view, he can see other people profiles. (I know how to do this.)
Step 2. User visits MyProfile.aspx page. Since his profile does not exist, details view, is blank with insert button enabled. User clicks the insert button and he can add his own profile only. (I dont know how to do this).
Step 3. Once users profile is added, it shows up on profiles.aspx page. He wants to update his own profile. He navigates to MyProfile.aspx page with ProfileID lets say 33.
DetailsView is able to pull up his profile based on profileid and update button is enabled. (I dont know how how to do this.)
Could some one please help me with step 2 and 3. I dont know how to setup sqldatasource and detailsview to accomplish this.
Thank you in advance.
Alright , I'll give you a simple solution which you can alter to fit to your needs.
For the Step 2:
You create a page which called create.aspx for example; in that page you put all the text boxes that you need and a button for registration. On the clicked event of that button write something as below
//using System.Data;
//using System.Data.Sql; you have to import these
//Put connection string
SqlConnection sqlcon = new SqlConnection("your connection string here which will be able to find in MSDN");
sql.Open();
SqlCommand sqlcmd = new SqlCommand("INSERT INTO Statement which easily find in MSDN too",sqlcon);
sqlcmd.ExecuteNoneQuery();
sql.Close();
Which this code you can insert into database whatever you want. In the INSERT INTO string you concatenate your inputs but be very careful that may cause SqlInjection bug which is very dangerous.(Please read articles about it).
For Step 3:
everything is all the same except instead of putting "INSERT ...." statement you have to use "UPDATE ..." statement which can find on MSDN.
Regards,
Pooria.
see following example........
source file .aspx
i am using gridview and detailsview for insert,update,edit a truckmaster table.
do the following steps:
1.take a gridview.assign datakeynames as your unique column from table.you can write boundfields for your each field.Infact that is better way.
2. take datasource control.Bind it to your table.
3.bind this datasource to Gridview.you will understand this steps better once you go through the following code.
4.Take a detailsview.Assign datakeynames as your unique column from table.
5.Take another datasource.Bind it to same table.declare insertcommand,selectcommand.
declare select parameter,updateparameter as in below code.
Hope it will help you.
<asp:GridView id ="gridTruckMaster"
runat ="server"
CssClass ="GridView"
DataKeyNames ="TruckType"
DataSourceID ="SqlDataSource1"
AutoGenerateColumns ="False"
ShowFooter ="True"
AllowPaging ="True">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></FooterStyle>
<RowStyle VerticalAlign="Top" BackColor="#F7F6F3" ForeColor="#333333"></RowStyle>
<Columns>
<asp:BoundField DataField="TruckType" HeaderText="TruckType" SortExpression="TruckType"></asp:BoundField>
<asp:BoundField DataField="TruckCapacity" HeaderText="TruckCapacity" SortExpression="TruckCapacity"></asp:BoundField>
<asp:CommandField ShowSelectButton="True"></asp:CommandField>
</Columns>
<PagerStyle BackColor="#284775" HorizontalAlign="Center" ForeColor="White"></PagerStyle>
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White"></SelectedRowStyle>
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></HeaderStyle>
</asp:GridView>
<asp:SqlDataSource ID ="SqlDataSource1"
runat ="server"
ConnectionString ="<%$ ConnectionStrings:GodrejReporterConnectionString %>"
SelectCommand ="SELECT [TruckType], [TruckCapacity] FROM [tbl_TruckMaster]"></asp:SqlDataSource>
<asp:DetailsView id ="dtlviewTruckMaster"
runat ="server"
CssClass ="GridView"
Width ="125px"
DataKeyNames ="TruckType"
Height ="50px"
AutoGenerateRows ="False"
HeaderText ="Truck Details"
><Fields>
<asp:BoundField DataField="TruckType" HeaderText="TruckType" ReadOnly="True"></asp:BoundField>
<asp:BoundField DataField="TruckCapacity" HeaderText="TruckCapacity"></asp:BoundField>
<asp:CommandField ShowInsertButton="True"></asp:CommandField>
<asp:CommandField ShowEditButton="True"></asp:CommandField>
</Fields>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></FooterStyle>
<RowStyle VerticalAlign="Top" BackColor="#F7F6F3" ForeColor="#333333"></RowStyle>
<EditRowStyle Width="250px" Height="10px"/>
<InsertRowStyle Width="250px" Height="10px" />
<PagerStyle HorizontalAlign="Center" BackColor="#284775" ForeColor="White"></PagerStyle>
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></HeaderStyle>
<CommandRowStyle BackColor="#5D7B9D" />
</asp:DetailsView>
<asp:SqlDataSource ID ="SqlDataSource2"
runat ="server"
ConnectionString ="<%$ ConnectionStrings:GodrejReporterConnectionString %>"
SelectCommand ="SELECT [TruckType], [TruckCapacity] FROM [tbl_TruckMaster] where TruckType=#pTruckType"
insertcommand ="insert into tbl_TruckMaster(TruckType,TruckCapacity) values(#TruckType,#TruckCapacity)"
updatecommand ="update tbl_TruckMaster set TruckCapacity=#TruckCapacity where TruckType=#pType"
>
<SelectParameters>
<asp:ControlParameter ControlID="gridTruckMaster" Name="pTruckType" PropertyName="SelectedValue" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter ControlID="gridTruckMaster" Name="pType" PropertyName="SelectedValue" />
</UpdateParameters>
</asp:SqlDataSource>
If you getting problem you can mail me at tbchandgude#gmail.com
Related
I am trying to automate some scenarios using protractor where we need to verify whether the data is updating in dynamic table.
Please find below
HTML Code:
enter image description here
Table in page:
enter image description here
It can be done by verifying that element is present in the DOM with the added Group ID or Group Name.
For Group ID:
element(by.xpath("*//table//tbody//tr//td[1]//p[text()='Amanda Test
Group']")).isDisplayed()
For Group name:
element(by.xpath("*//table//tbody//tr//td[2]//p[text()='Amanda
Group']")).isDisplayed()
I'm assuming you're using Angular2+, yes?
In your HTML Template, you are probably using an *ngFor directive to populate the table dynamically. Add an index to the *ngFor (it's best practices for updating the DOM) in order to add a dynamic id to each element:
<tr *ngFor="let user of user; index as u" id="user-{{u + 1}}">
<td id="userName-{{u + 1}}">
{{user.firstName}} {{user.userName}}<br />
{{user.userName}}
</td>
<td id="userRoles-{{ u + 1 }}">
<span id="role-{{u + 1}}-{{ r + 1 }}" *ngFor="let role of user.roles; index as r">
{{ role.toUpperCase() + ', '}}
</span>
</td>
<!- Omitted code -->
</tr>
In your Page Object:
// Get first user on the table
get firstUser() {
return element(by.id('user-1');
}
// Get a specific user by id
public getUser(index: number) {
return element(by.id(`user-${index}`);
}
// Get all of the attributes for a single user by id
get userAttributes(index: number) {
return element.all(by.id(`user-${index}`);
}
I am not a fan of xpath selectors. Yes, they are faster. But in code that is dynamic or changes frequently, they are the most fragile of selectors. There is no reason your dynamic data cannot have a dynamic ID that clearly identifies each portion of the code you need.
Good luck!
So here is my quick code.
var thisisformykeyorid =$scope.id;
var ref = firebase.database().ref('/myusers/').child("users");
$scope.users= $firebaseArray(ref);
var query = ref.orderByChild("timestamp").limitToLast(100);
$scope.filteruser= $firebaseArray(query);
In my HTML is
<div ng-repeat="samplein filteruser>
<h2>{{ sample.firstname}}</h2>
<p>{{ sample.age}}</p>
</div>
So in firebase there are unique id or keys for each set of data.
How do i add a filter or query to select a set of data from firebase using my variable ? (assuming $scope.id is a unique key) Please be guided that i dont want to use ng-repeat anymore because i only want to view only 1 set of data. Need help
If you know what object you want to display, you can use $firebaseObject instead of $firebaseArray:
var ref = firebase.database().ref('/myusers/').child("users");
$scope.user = $firebaseObject(ref.child($scope.id));
And then display it in your HTML with:
<div >
<h2>{{user.firstname}}</h2>
<p>{{user.age}}</p>
</div>
I have the following jsp code which uses struts tag:
<input type = "radio"
id = "<s:property value="name"/>"
name = "<s:property value="name"/>"
value = "<s:property value="value"/>"
<s:if test="fieldValue==null">
<s:if test="defaultOption==true">
checked="checked"
</s:if>
</s:if>
<s:else>
<s:if test="value==fieldValue">
checked="checked"
</s:if>
</s:else>
/>
Eclipse says that:
Start tag (input) not closed properly, expected >.
But I cannot find where is the error. Please help.
It is probably an eclipse bug because with Netbeans there is no error
if you dont want to see the error with Eclipse (and in that case only) :
in the first if, put test like that :
fieldValue==null && defaultOption==true
and get rid of the internal if
it should be the same
PS : try to find a way to use s:radio maybe
Eclipse complains because it does not accept tags (for example <s:if>) inside input tag, you can deactivate JSP validation as suggested in comments .
Go to project properties and uncheck JSP Content Validator, then clean your project
If you don't want to disable validation, here is a suggested solution:
<s:if test="fieldValue==null">
<s:if test="defaultOption==true">
<input type = "radio" id = "<s:property value="name"/>" name = "<s:property value="name"/>" value = "<s:property value="value"/>" checked="checked" />
</s:if>
</s:if>
<s:else>
<s:if test="value==fieldValue">
<input type = "radio" id = "<s:property value="name"/>" name = "<s:property value="name"/>" value = "<s:property value="value"/>" checked="checked" />
</s:if>
</s:else>
Just as a note, your JSP code give same result(I guess it's just for illustration :) ).
I currently update my database records with an input like this
$this->my_model->update($id, $this->input->post()));
(This is after I have performed a validation on all the input. The "model" also has a white_list of data to expect.)
Problem: if I am updating a checkbox, and it is "unticked" (i.e. 'false') - then that field is not 'posted' by the browser.
For example - if I tick checkbox_two - but leave checkbox_one unticked, $_POST shows:
[field_one] = "some value"
[field_two] = "some value"
[checkbox_two] = 1
Therefore my model will not update that field - since it is not part of the post.
The same does not happen in reverse - because a "ticked" checkbox is posted as "1" - and thus is correctly updated.
[field_one] = "some value"
[field_two] = "some value"
[checkbox_one] = 1
[checkbox_two] = 1
Question: Does anyone have an elegant solution to handle this, other than having to always specifically check for each checkbox?
<input type="hidden" name="example" value="FALSE" />
<input type="checkbox" name="example" value="TRUE" />
This practice is easy and logical. If checkbox is checked, $this->input->post('example') == 'TRUE' else, $this->input->post('example') == 'FALSE'.
The latest given value of a name="" overrides previous, thus givin prio checkbox > hidden.
EDIT: this solution is equal to given most rated answer in Rick Calder's comment. I've also come to this conclusion on my own, though.
I'm tring to implement the classic functionality of this select:elements depends on this other select:selection using Lift, E.g. select the country and get the possible states for the selected country.
The problem that I'm facing is that the "this.myForm.submit()" that I have inside the onchange of the select element is not firing the ajax request. If I use an input type"submit" it works perfectly.
Is this behaivior related with Lift framework? Is there a better way of implementing this kind of functionality using Lift libraries?
The relevant snipped code:
"name=distributionPoints" #> SHtml.select(distributionPoints, Empty, selectedDistributionPoint = _, "id" -> "the_distributionPoints") &
"name=devices" #> (SHtml.select(devices, Empty, selectedDevice = _, "id" -> "the_devices") ++ SHtml.hidden(process))
The view html:
<form class="lift:form.ajax">
<select name="distributionPoints" id="the_distributionPoints" onchange="submit()">
<option></option>
</select>
<br/>
Device:
<select name="devices" id="the_devices">
<option></option>
</select>
</form>
The rendered HTML:
<form id="F391649920812YBACEZ" action="javascript://" onsubmit="liftAjax.lift_ajaxHandler(jQuery('#'+"F391649920812YBACEZ").serialize(), null, null, "javascript");return false;">
<div>
Punto de distribuciĆ³n:
<select onchange="submit()" id="the_distributionPoints" name="F630704816482OLP514"></select>
<br />
Equipo:
<select name="F391649920817BLRJW5" id="the_devices"></select><input type="hidden" name="F391649920818HPS35E" value="true" />
<br />
</div>
</form>
[edit]
I finally got the solution. Like Chris mentioned I used ajaxSelect instead of just selects and instead of using setHtml there's a method called JsCmds.ReplaceOptions that does exactly what I was looking for.
You should understand that when using Ajax submit the page is not reloaded. So I would suggest you to use JsCmds.setHtml on server side to "reset" the second select element.
So, in fact the first select is an ajaxSelect which is meant to modify the second one (so it is not concerned by the hidden submit in my opinion). The second select is updated when the first one is changed, using 'selectPoint(s)'
Piece of Scala code
def selectPoint(s):JsCmd = {
selectedDistributionPoint = s;
newDevices:List[String] = findCorrespondingDevices(s);
JsCmds.setHtml("name=devices", SHtml.select(newDevices, Empty, selectedDevice = _, "id" -> "the_devices")) ++ SHtml.hidden(process))
}
"name=distributionPoints" #> SHtml.AjaxSelect(distributionPoints, Empty, s=> selectPoint(s), "id" -> "the_distributionPoints") &
"name=devices" #> (SHtml.select(Nil, Empty, selectedDevice = _, "id" -> "the_devices") ++ SHtml.hidden(process))
Piece of template code
<input name="distributionPoints" id="the_distributionPoints" onchange="submit()"/>
<input name="devices" id="the_devices"/>