Google Answers Logo
View Question
 
Q: ASP.NET 2.0 AND C# HOW DO I? DATA ( No Answer,   0 Comments )
Question  
Subject: ASP.NET 2.0 AND C# HOW DO I? DATA
Category: Computers > Programming
Asked by: 1stmiami-ga
List Price: $15.00
Posted: 18 Sep 2006 12:29 PDT
Expires: 18 Sep 2006 16:29 PDT
Question ID: 766340
1. In ASP.NET 2.0 Is there a setting that sets all current and future controls on a
page to position absolute automatically so that I don't have to set
each one manually?

2. In ASP.NET 2.0 I'd like to code have a "New" button, that when selected makes
visible a detailview in insert mode and with only the insert command
available. I would imagine I'd be adding an onclick event for the
button that makes the control visible, but how would I graphically
configure edittemplate (I think) for the control to only exist in
insert mode? Perhaps my approach is wrong.

3. In C#, How do I dynamically set the ErrorMessage value of a custom validator?

This code works with the preset ErrorMessage.

 protected void CustomValidator1_ServerValidate(object source,
ServerValidateEventArgs args)
    {
        if (TextBox1.Text.Length < 1)
        {
            args.IsValid = false;
        }
    } 

4. IN C#, regarding Generic List and a Datasource that is using a
business object to pull data via a stored procedures into a Generic
list.

I'm trying to take apart the dotNet Time Tracker dotNet C# starterkit
sample application and replicate a part of the code.

At a high level, I have a very simple SQL server table and stored
procedure which I have no problems binding from directly from an
ASP.NET control...

Table BOOK
name varchar(50)
phone varchar(10)

ALTER procedure "jcp1"
@name varchar(50) AS
SELECT phone FROM book where name = @name

What I'm trying to do is return a dataview given a textbox value passed
to to the stored procedure, but using C# method and List<> like they do
in the sample Ap. Eventough I might not need to, I'm trying to  use a
generic List but I'm just not getting it.

I reverted my code to the closest working revision, the below code is
apparently fetching the correct row, however I am unable to see or list
no other other items except LENGTH of the returning field when
configuring the control in the UI . I suspect this is because I'm using
List<string> and not List<whaterver>.

The Dataview source is the method getphone() with a where clause of a
textbox = name
The idea being, if I enter "Jason" in the texbox, the dataview would
list phone with name "Jason"..

I'm sure there is more right than wrong with the below - I just taking
shots in the dark at this point.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Collections;
using System.Text;

/// <summary>
/// Summary description for jcp
/// </summary>
///

public class book
{
    private string name;
    private string phone;

}

public class jcp
{

    private delegate void TGenerateListFromReader<T>(SqlDataReader
returnData, ref List<T> tempList);
    /**** connection string */
    public static string ConnectionString =
ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

    public static List<string> GetPhone(string name) {
      SqlCommand sqlCmd = new SqlCommand();
      AddParamToSQLCmd(sqlCmd, "@name", SqlDbType.NText, 50,
ParameterDirection.Input, name);
      SetCommandType(sqlCmd, CommandType.StoredProcedure, "jcp1");
      List<string> userList = new List<string>();
      TExecuteReaderCmd<string>(sqlCmd, TGeneratephone<string>, ref
userList);
      return (userList);
    }

    #region SQL HELPER

    protected static void AddParamToSQLCmd(SqlCommand sqlCmd,
                                 string paramId,
                                 SqlDbType sqlType,
                                 int paramSize,
                                 ParameterDirection paramDirection,
                                 object paramvalue)
    {

        if (sqlCmd == null)
            throw (new ArgumentNullException("sqlCmd"));
        if (paramId == string.Empty)
            throw (new ArgumentOutOfRangeException("paramId"));

        SqlParameter newSqlParam = new SqlParameter();
        newSqlParam.ParameterName = paramId;
        newSqlParam.SqlDbType = sqlType;
        newSqlParam.Direction = paramDirection;

        if (paramSize > 0)
            newSqlParam.Size = paramSize;

        if (paramvalue != null)
            newSqlParam.Value = paramvalue;

        sqlCmd.Parameters.Add(newSqlParam);
    }

    private static void SetCommandType(SqlCommand sqlCmd, CommandType
cmdType, string cmdText)
    {
        sqlCmd.CommandType = cmdType;
        sqlCmd.CommandText = cmdText;
    }

    private static void ExecuteScalarCmd(SqlCommand sqlCmd)
    {
        if (ConnectionString == string.Empty)
            throw (new
ArgumentOutOfRangeException("ConnectionString"));

        if (sqlCmd == null)
            throw (new ArgumentNullException("sqlCmd"));

        using (SqlConnection cn = new SqlConnection(ConnectionString))
        {
            sqlCmd.Connection = cn;
            cn.Open();
            sqlCmd.ExecuteScalar();
        }
    }

    private static void TExecuteReaderCmd<T>(SqlCommand sqlCmd,
TGenerateListFromReader<T> gcfr, ref List<T> List)
    {
        if (ConnectionString == string.Empty)
            throw (new
ArgumentOutOfRangeException("ConnectionString"));

        if (sqlCmd == null)
            throw (new ArgumentNullException("sqlCmd"));

        using (SqlConnection cn = new SqlConnection(ConnectionString))
        {
            sqlCmd.Connection = cn;

            cn.Open();

            gcfr(sqlCmd.ExecuteReader(), ref List);
        }
    }

    private static void TGeneratephone<T>(SqlDataReader returnData, ref
List<string> phoneList)
    {
        while (returnData.Read())
        {
            string phone = (string)returnData["phone"];
            phoneList.Add(phone);
        }
    }

    #endregion SQL HELPER

}
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy