Click here to Skip to main content
15,896,201 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionHandle master page button(s) click events on content page Pin
De_Novice23-Mar-11 6:13
De_Novice23-Mar-11 6:13 
AnswerRe: Handle master page button(s) click events on content page Pin
De_Novice23-Mar-11 6:19
De_Novice23-Mar-11 6:19 
QuestionMaskedEdit extender and special characters Pin
Peterson Luiz23-Mar-11 5:03
Peterson Luiz23-Mar-11 5:03 
QuestionPaste data from excel Pin
Hum Dum22-Mar-11 23:00
Hum Dum22-Mar-11 23:00 
AnswerRe: Paste data from excel Pin
Dalek Dave23-Mar-11 5:03
professionalDalek Dave23-Mar-11 5:03 
AnswerRe: Paste data from excel Pin
Pavel Yermalovich23-Mar-11 22:47
Pavel Yermalovich23-Mar-11 22:47 
QuestionHow to save data and retrieve data from database using two tables in gridview? Pin
snamyna22-Mar-11 21:55
snamyna22-Mar-11 21:55 
AnswerRe: How to save data and retrieve data from database using two tables in gridview? Pin
ktrrzn5-Apr-11 19:32
ktrrzn5-Apr-11 19:32 
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);                       // u need to create connection string and query string to fill the data from database.
DataTable dtQuestion = dsTable["Question"]; // assign data result from question dataset
DataTable dtAnswer   = dsTable["Answer"]; // assign data result from answer dataset
DataTable dtBind = dtQuestion.Clone();  // copy all data from Question
dtBind.Columns.Add("Answer",System.Type.GetType("System.Boolean"));  // create new column "Answer" with Boolean type, 1 for yes and 0 for no

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"])  // i assume that u used QuestionId as primary key for both Tables
      {
         dtBind.Rows[index]["Answer"] = dtAnswer.Rows[j]["Answer"];
         break;                                                      // break from inner loop
      }
    }
}


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);   // this will save all changes back to database


here[^] is an example of how to update.


Hope it works!
GeneralRe: How to save data and retrieve data from database using two tables in gridview? Pin
snamyna6-Apr-11 14:35
snamyna6-Apr-11 14:35 
AnswerRe: How to save data and retrieve data from database using two tables in gridview? Pin
ktrrzn6-Apr-11 15:12
ktrrzn6-Apr-11 15:12 
GeneralRe: How to save data and retrieve data from database using two tables in gridview? Pin
snamyna6-Apr-11 19:13
snamyna6-Apr-11 19:13 
QuestionHow to Convert ASP.NET web application to ASP.NET Web Service Application Pin
VenkataRamana.Gali22-Mar-11 20:51
VenkataRamana.Gali22-Mar-11 20:51 
QuestionAccess content page procedure from master page button Pin
De_Novice22-Mar-11 6:50
De_Novice22-Mar-11 6:50 
AnswerRe: Access content page procedure from master page button [modified] Pin
Not Active22-Mar-11 7:47
mentorNot Active22-Mar-11 7:47 
GeneralRe: Access content page procedure from master page button Pin
De_Novice22-Mar-11 7:55
De_Novice22-Mar-11 7:55 
GeneralRe: Access content page procedure from master page button Pin
Not Active22-Mar-11 8:02
mentorNot Active22-Mar-11 8:02 
GeneralRe: Access content page procedure from master page button Pin
De_Novice22-Mar-11 8:08
De_Novice22-Mar-11 8:08 
GeneralRe: Access content page procedure from master page button Pin
Not Active22-Mar-11 8:28
mentorNot Active22-Mar-11 8:28 
GeneralOff Topic Pin
Rajesh R Subramanian23-Mar-11 22:06
professionalRajesh R Subramanian23-Mar-11 22:06 
QuestionGive me Suggestions to maintain security for websites Pin
Rajeshwar Code- Developer22-Mar-11 2:27
Rajeshwar Code- Developer22-Mar-11 2:27 
AnswerRe: Give me Suggestions to maintain security for websites Pin
Richard MacCutchan22-Mar-11 4:25
mveRichard MacCutchan22-Mar-11 4:25 
AnswerRe: Give me Suggestions to maintain security for websites Pin
thatraja22-Mar-11 4:49
professionalthatraja22-Mar-11 4:49 
AnswerRe: Give me Suggestions to maintain security for websites Pin
Dalek Dave22-Mar-11 5:06
professionalDalek Dave22-Mar-11 5:06 
JokeRe: Give me Suggestions to maintain security for websites Pin
Not Active22-Mar-11 6:15
mentorNot Active22-Mar-11 6:15 
GeneralRe: Give me Suggestions to maintain security for websites Pin
Paladin200022-Mar-11 6:28
Paladin200022-Mar-11 6:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.