Solved

moving sql variable values from a aspx page to local varibles

Posted on 2006-10-28
5
248 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

867 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

13 Experts available now in Live!

Get 1:1 Help Now