?
Solved

load gridview textbox with more data after databind

Posted on 2011-03-24
5
Medium Priority
?
436 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 5

Expert Comment

by:soujanya_g
ID: 35207191
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
ID: 35207661
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 2000 total points
ID: 35213885
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
ID: 35353360
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
ID: 35397680
thanks
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

770 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