[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

load gridview textbox with more data after databind

Posted on 2011-03-24
5
Medium Priority
?
441 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 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