Solved

load gridview textbox with more data after databind

Posted on 2011-03-24
5
417 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
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 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 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

12 Experts available now in Live!

Get 1:1 Help Now