[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 446
  • Last Modified:

load gridview textbox with more data after databind

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
kdeutsch
Asked:
kdeutsch
  • 3
1 Solution
 
soujanya_gCommented:
Hi

You can do this by,getting  the value from database in rowdatabound  and fill the text field  by finding it in gridview
0
 
kdeutschAuthor Commented:
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
 
mr_nadgerCommented:
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
 
kdeutschAuthor Commented:
All,

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now