|
|
Hello guys..
I've been searching for a solution of my problem weeks ago but it did not work out.
My problem goes like this:
I am using a gridview and use a sqldatasource to retrieve the data in database to display the questions that the users need to answer. Then, i add new column for answer column where in that column, i put a radiobuttonlist with Yes/No options.
I have been used the sqldatasource to retrieve the data earlier, so of course it is impossible to use one more sqldatasource to save the answer entered by the users. for your information, the answer column is from different table in same database with the question table. How is it to make possible to retrieve the data and save the data in different table in gridview?
Please, i really need your help..
Thanks for your time.
|
|
|
|
|
Hi snamyna,
As far as i know, in your problem, u can combine these two tables into one if they used QuestionId as primary key and if
there is only one Answer for each Question in your database tables.
If don't want to combine, here is some suggestion.
you can use three temp DataTables : one for question and another one for answer.
and final one for combination of both. u must declare SqlDataAdapter to Fill the DataSet and to Update them back.
see example in : here[^] and here[^]
DataSet dsTable = new DataSet();
adapter.Fill(dsTable);
DataTable dtQuestion = dsTable["Question"];
DataTable dtAnswer = dsTable["Answer"];
DataTable dtBind = dtQuestion.Clone();
dtBind.Columns.Add("Answer",System.Type.GetType("System.Boolean"));
for(int index=0;index < dtBind.Rows.Count;index++)
{
for(int j=0; j < dtAnswer.Rows.Count; j++)
{
if(dtBind.Rows[index]["QuestionId"].Equals(dtAnswer.Rows[j]["QuestionId"])
{
dtBind.Rows[index]["Answer"] = dtAnswer.Rows[j]["Answer"];
break;
}
}
}
and bind it to gridview from codebehind file.(.asp.cs)
GridView1.DataSource = dtBind;
GridView1.DataBind();
you need to change your girdview databound column
<ItemTemplate>
<asp:RadioButton ID="rdbYes" runat="server" Text="Yes" Checked='<%# Eval("Answer") %>' GroupName="Answer" />
<asp:RadioButton ID="rdbNo" runat="server" Text="Yes" Checked='<%# !Eval("Answer") %>' GroupName="Answer" />
</ItemTemplate>
When u click Submit button(when post back occur),
u need to manually check every rows of Answer column(radionbutton ) in GridView .
declare Boolean variable and assign the value from one of radionButton .
need to save by using SqlDataAdapter with Update method.
And assign the result back to dtAnswer.Rows["Answer"];
adapter.Update(dsTable);
here[^] is an example of how to update.
Hope it works!
|
|
|
|
|
Hye ktrrzn..
Thanks for your reply but i have come out with the solution earlier where I just retrieve the data to insert to the gridview by using SqlDataSource, but for saving the other column in the gridview into the database, I am using Sql query in .vb file instead of SqlDataSource.
Now I got another problem where I want to display all data that has same max values. Do u have any idea where should I rewrite so that I can display all the data? I have debugging this code but there's no error. After running it, all the data came out was the same.
This is the overview of my data.
Career - Marks
Medical - 12
Sport Science - 12
Dietetic - 12
Optometry - 12
Physiology - 12
Medical Laboratory Technology - 12
Biomedical - 12
Audiology - 12
Forensic - 12
Veterinary - 12
The result that came out after running my code is :
Veterinary - 12
Veterinary - 12
Veterinary - 12
Veterinary - 12
Veterinary - 12
Veterinary - 12
Veterinary - 12
Veterinary - 12
Veterinary - 12
Veterinary - 12
So how to display all different careers with the same marks?
This is my vb code.
Dim connString As String = "Data Source=AINA-PC;Initial Catalog=LaluanKerjaya;Integrated Security=True"
Dim con As SqlConnection = New SqlConnection(connString)
Dim kp As String = CType(Session.Item("KP"), String)
Dim noic As String = CType(Session.Item("NOIC"), String)
KPLabel.Text = noic
Dim cmdQuery As String = "SELECT count(Career) FROM Analysis WHERE Jumlah = (SELECT MAX(Marks) FROM Analysis ) AND UserID = '" + kp + "'"
Dim cmd As SqlCommand = New SqlCommand(cmdQuery, con)
Dim dr As SqlDataReader
Dim labelCount As Integer
Dim career As String
con.Open()
dr = cmd.ExecuteReader()
While dr.Read()
labelCount = dr.GetValue(0)
End While
dr.Close()
For i As Integer = 0 To labelCount - 1
' Create the label control and set its text attribute
Dim Label1 As New Label
Dim cmdQuery2 As String = "SELECT Career FROM Analysis WHERE Marks= (SELECT MAX(Marks) FROM Analysis ) AND UserID = '" + kp + "'"
Dim cmd2 As SqlCommand = New SqlCommand(cmdQuery2, con)
Dim dr2 As SqlDataReader = cmd2.ExecuteReader()
'con.Open()
While dr2.Read()
career= dr2("Career").ToString()
'Session("CAREER") = career
End While
dr2.Close()
Label1.Text = career
cmd2.ExecuteNonQuery()
cmd2.Parameters.Clear()
'con.Close()
Dim Literal1 As New Literal
Literal1.Text = "<br />"
' Add the control to the placeholder
PlaceHolder1.Controls.Add(Label1)
PlaceHolder1.Controls.Add(Literal1)
Next
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
con.Close()
|
|
|
|
|
hi snamyna,
I think you are looping unnecessarily twice.
Bcoz u already know the loop count of ur career that has Max marks
The only for loop is sufficient, u don't need while loop as usual.
I think, in ur mind, u confuse that SqlDataReader should be loop at the end of file.
it is correct for common. but in ur case, u already know the loop count.
Another problem is u assign the value dr2 to career (same variable) till the end of while loop
without adding to placeholder, after u finish career variable will hold last value of
dr2<br /> so, u end up with last value and when u add to PlaceHolder1 the Label1.Text is last value.
And then u loop again with For loop and start to query again, get the rows and while loop again
loop until to last value and end up with last value, assign it to Label1.Text with exactly the same value(last row).
So, as a suggestion, u juz re-arrange ur coding logic.
Here:
Dim cmdQuery2 As String = "SELECT Career FROM Analysis WHERE Marks= (SELECT MAX(Marks) FROM Analysis ) AND UserID = '" + kp + "'"
Dim cmd2 As SqlCommand = New SqlCommand(cmdQuery2, con)
Dim dr2 As SqlDataReader = cmd2.ExecuteReader()
'con.Open()
For i As Integer = 0 To labelCount - 1 '
' Create the label control and set its text attribute
Dim Label1 As New Label
dr2.Read()
career= dr2("Career").ToString()
Label1.Text = career '
Dim Literal1 As New Literal
Literal1.Text = "<br />"
' Add the control to the placeholder
PlaceHolder1.Controls.Add(Label1)
PlaceHolder1.Controls.Add(Literal1)
Next
dr2.Close()
If u query is right, the problem is the order of ur coding logic.
Hope it works!
|
|
|
|
|
Thanks! That works very well. sorry to be so you-know-what. Thanks again!
|
|
|
|
|
Hi All,
I have one web application which is having asmx web service files(created using 2.0). Now i have added few svc files to the same web application.
Anyone please tell me, how do i convert this application to ASP.NET Web Service Application (3.5)
I have seen a option, where you can "Convert to web Application" option for Web Service Applications. But I need vice versa procedure.
pleeeeeeeeeeeeeease help me.
Ramana
|
|
|
|
|
Hi Gurus,
This is the situation:-
I have a master page (masterpage.master) that contains a save button (btn_save). There are 3 contentpages that inherit this master page, each content page needs to use the save button but use the procdure for the content page. How do I make this happen that when user is on contentpage1 and user clicks save button, the procedure to save for contentpage1 is executed.
I am new to .net and have searched the web but in vain. Will appreciate any help. I am using Vb.net ,kindly reply with code / explanation in vb.
Thanks
|
|
|
|
|
You could create an event which the content page would subscribe to then handle the button click event on the master page and raise the event
public EventHandler<EventArgs> Submit;
public void OnSubmit(object sender, EventArgs e)
{
EventHandler<EventArgs> handler = Submit;
if (handler != null)
{
handler(sender, e);
}
} In your content page
public void OnInit(...)
{
((MyMaster)Page.Master).Submit += new EventHandler<EventArgs>(OnSubmit);
}
public void OnSubmit(object sender, EventArgs e)
{
}
I know the language. I've read a book. - _Madmatt
modified on Tuesday, March 22, 2011 1:56 PM
|
|
|
|
|
I do not understand , where would you create the event in the code behind of master page? Could you give soe more explanation and codesnipped vb?
|
|
|
|
|
The first snippet is in your master page, the second, as indicated, is in your content page.
What more explaination do you require?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
what will the EventArgs be? How does this work. Can you give me a working example?
Thank you for your time.
|
|
|
|
|
This is a working example.
I understand you are a novice but you don't seem to have a base from which to understand this. There is nothing more I can explain if you don't understand basic event handling in .net. I would suggest you pick up a book on ASP.NET and work through it. Then, if you still don't understand how this works, come back and ask more questions.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi Mark,
I've a few licenses of ESET NOD32 to be given away (It's fully functional, free, no strings attached, and nothing expected in return), and I chose a few people whom I think are contributing on the programming forums regularly. If you'd like one of those licenses, drop me a line.
You could write to me at rajesh AT indiamvps DOT net
Regards,
Rajesh.
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
HI
my next project is online exam project.
My boss ask me some sugessions about security for online exam.
Please Suggest me. How can i provide security. and bla bla bla.
try and try untill reach success..
|
|
|
|
|
Rajeshwar Code- Developer wrote: and bla bla bla.
And you expect a sensible response to this?
I must get a clever new signature for 2011.
|
|
|
|
|
In CP there is a section for Web Security[^] so browse the articles there...do what do you want.
|
|
|
|
|
Private individual log in details is a start, also confirmation of payment of course fees.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
Make sure to hard-code your connection strings in your webpages and make use of plenty of string concatenations to form inline sql statements.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
Guess you didn't get the joke
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Nah, I got it; but I've seen such things in production code.
Besides, you forgot to make sure it included raw user input in those concatenations, particularly when he is stringing-together DDL.
|
|
|
|
|
|
|
Hi...
In my application i used timer for data update. Want to show graph view via asp chart control. Timer calling every 2sec once data available in the database that information populate to chart then show its to page. Once data got i disabled the timer ( timer1.Enable = false). After that timer call once again in page_load callback method.
How can restrict these. Is possible to make synchronized call in asp timer
Thanks
|
|
|
|