Solved

moving sql variable values from a aspx page to local varibles

Posted on 2006-10-28
5
246 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

14 Experts available now in Live!

Get 1:1 Help Now