Solved

load gridview textbox with more data after databind

Posted on 2011-03-24
5
413 Views
Last Modified: 2012-05-11
What I have is a gridview that pulls up a bunch of question for a user to answer.  It has the question a radio button for a go/nogo and 3 textboxes, one for additional data, one for remarks and one for a date.  I have 21 questions where I have to fill in that extra data filed with  data from a certain dtabase field.  My issues is how to get that data in there.  All 21 questions are different database pulls fro one person that match a question.

How can I rebind individual sql pulls to certain questions in a grid and put that data in the textbox.
Gridview
<asp:GridView ID="myGridDental" runat="server" Font-Size="12" HeaderStyle-HorizontalAlign="Center" BorderWidth="1px" CellPadding="6" GridLines="Both" 
                                        BorderColor="#404040" Font-Names="Veranda,arial,sans-serif" AutoGenerateColumns="false" CellSpacing="0" RowStyle-HorizontalAlign="Center" Width="100%"
                                        DataKeyNames="intQuestionId"><AlternatingRowStyle BackColor="#b0c4de" /><HeaderStyle Font-Bold="true" ForeColor="White" BackColor="SteelBlue" />
                                            <Columns>
                                                <asp:BoundField DataField="strQuestion" HeaderText="Question" ItemStyle-HorizontalAlign="Left" />
                                                <asp:TemplateField HeaderText="GO\NOGO">
                                                <ItemTemplate>
                                                    <asp:RadioButtonList ID="rblDental" runat="server" RepeatDirection="Horizontal" CellPadding="5" CellSpacing="5" TextAlign="Right">
                                                        <asp:ListItem Value="0">GO</asp:ListItem>
                                                        <asp:ListItem Value="1">NO\GO</asp:ListItem>
                                                    </asp:RadioButtonList>
                                                    <asp:RequiredFieldValidator ID="valDRadio" runat="server" ControlToValidate="rblDental" ErrorMessage="Not Answered" ForeColor="Red" ValidationGroup="Dental" />
                                                </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Data">
                                                <ItemTemplate>
                                                    <asp:TextBox ID="txtData" runat="server" Width="60"></asp:TextBox>
                                                </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Remarks">
                                                <ItemTemplate>
                                                    <asp:TextBox ID="txtRemarks" runat="server" Width="200"></asp:TextBox>
                                                </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Record Date">
                                                <ItemTemplate>
                                                    <asp:TextBox ID="txtCal" runat="server" Width="100" style="cursor:pointer"></asp:TextBox>
                                                    <asp:CalendarExtender ID="txtCal_CalendarExtender" runat="server" TargetControlID="txtCal" />                                                            
                                                </ItemTemplate>
                                                </asp:TemplateField>
                                            </Columns>
                                            </asp:GridView>



data pull that brings in questions
 sql = "Select sc.intQuestionID, q.strQuestion, q.intCategoryID, ac.strAdminCategory from tblSRPCreate as sc Left JOIN tblSRPQuestion as q on q.intQuestionId = sc.intQuestionId LEFT JOIN tblAdminCategory as ac " _
                & "on ac.intAdminCatId = q.intAdminCatId where sc.intSRpId = " & SrpId & " order by q.intCategoryID, q.intAdminCatId "

            myDataTable = New DataTable
            myDataTable = getData(sql)


Individual statements pull the data for certain persons so they have a where clause to add the SSN to get the data.

Open in new window

0
Comment
Question by:kdeutsch
  • 3
5 Comments
 
LVL 5

Expert Comment

by:soujanya_g
Comment Utility
Hi

You can do this by,getting  the value from database in rowdatabound  and fill the text field  by finding it in gridview
0
 

Author Comment

by:kdeutsch
Comment Utility
soujanya_g:

Now sure what you are getting at but here is what i have.  I load the initial gridview with the information above.  Then I haave 21 of the questions that have seperate sql statements I need to run to put that data back into the data field.

Q 1.
What iis your current name.

sql = "Select strFullname from Personnel.dbo.personnel where id = @SSN


Q2.
Is this your current SSN
sql = "Slect ssn ffrom personnel.dbo.tblSSN where SSN = @SSN

So what I need to know how to do is get the sql I need to run for each question, which I think i should be able to grab from a hidden field of the gridview ????  But then how do I run it for everyrow that contains this sql data.
0
 
LVL 7

Accepted Solution

by:
mr_nadger earned 500 total points
Comment Utility
how about this for an approach:
Have a sql table listing the questions and the relevant sql query
using your example:
1, "What iis your current name", ""Select strFullname from Personnel.dbo.personnel where id = @SSN"
2, "Is this your current SSN","Select ssn ffrom personnel.dbo.tblSSN where SSN = @SSN"

then create a webuser control, with a questionnumber property, which calls the above questions table for the appropriate question and sql statement to run.
Inside your new control, you can easily control what happens and when, using the appropriate events (and ajax update panel to keep it smooth),
e.g. when the questionnumber property is set, a datasource populates the question box with the correct text and pulls your next sql statement to populate the next bit when the question is answered

In your main aspx page:
create a sql datasource pointing at the questions table
add a gridview, pointing at this datasource, with the question number index as a datakey
add a template field containing your webuser control to the gridview
add some code on the gridview's databound event to iterate through each row, setting the webuser control's questionnumber property to the question number held in that row's datakey

I know this probably sounds a bit like overkill, but using a similar method I've built up some grids on a skills development framework containing a simple webuser control with very little code and a lot of flexibility


0
 

Author Comment

by:kdeutsch
Comment Utility
All,

Still working on this have not been able to get back to it, becuase of more pressing matters, hopefully next week.
0
 

Author Closing Comment

by:kdeutsch
Comment Utility
thanks
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now