Solved

moving sql variable values from a aspx page to local varibles

Posted on 2006-10-28
5
250 Views
Last Modified: 2010-04-16
I am using a SqlDataSource (in asp 2.0 aspx page)  with a Gridview control, I would like to PrePopulate  the textboxes of a formview controls (Insert mode) whith the results (variable values) from the  Gridview.  I’m using C#.

      SqlDataSource1
SELECT  userId, rate, Lname, Fname
FROM   empl

I want to populate the following varibles in my aspx page. And prepopulat the textBoxes in a FormView control in Insert mode

Int    UserID
Int   Payrate
String  Lname
String  Fname

Can some one show me how to do this?
Thanks!
0
Comment
Question by:bmanmike39
5 Comments
 
LVL 12

Accepted Solution

by:
deanvanrooyen earned 500 total points
ID: 17831596
this is how you can manually bind a control or make your own form view

this is just with a repeater, there is a button that does the updating to give you an idea, this could even just be an html table with some server controls...

        <asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand"  >
        <ItemTemplate>
             <asp:Label ID="label1" Text='<%# Bind("ProductID") %>' runat="server" Width="50"  ></asp:Label>
             <asp:CheckBox id="chk" runat="server" Text="Discontinued?" Checked='<%# System.Convert.ToBoolean(Eval("Discontinued")) %>' Width="50"/>
             <asp:TextBox id="textbox" runat="server" Text='<%# Bind("Description") %>'
             <asp:Button id="btnUpdate" Runat="server" Text="Update" CommandName="Update" CommandArgument='<%# Eval("productID") %>' Font-Size="12px" Width="50"></asp:Button>
             <br />
         </ItemTemplate>
        </asp:Repeater>



    public void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        Int32 id = System.Convert.ToInt32(((Label)e.Item.FindControl("label1")).Text);
        Int16 check = System.Convert.ToInt16(((CheckBox)e.Item.FindControl("chk")).Checked);
        TextBox tb = (TextBox )e.Item.FindControl("textbox");
        //update the db
        string strcon = SqlDataSource1.ConnectionString;
        System.Data.SqlClient.SqlConnection sqlCon = new System.Data.SqlClient.SqlConnection(strcon);
        System.Data.SqlClient.SqlCommand sqlCmd = new System.Data.SqlClient.SqlCommand("update products set discontinued = @check,description = @desc  where productid = @id", sqlCon);
        sqlCmd.Parameters.Add("@id", SqlDbType.Int).Value = id;
        sqlCmd.Parameters.Add("@check", SqlDbType.Int).Value = check;
        sqlCmd.Parameters.Add("@desc ", SqlDbType.Int).Value = tb.Text;
       
        try
        {
            sqlCon.Open();
            sqlCmd.ExecuteNonQuery();
            sqlCon.Close();
            //rebind the repeater
        }
        catch(Exception me)
        {

        }  
    }

             
0
 

Author Comment

by:bmanmike39
ID: 18047352
I have had to address a urgent  project and have not been able to test the answer given.  I am hoping to get back to that project in the next week or so.  Sorry about the time.  So please leave it posted for now, if that is possible.

Thank you
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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