نمایش نتایج 1 تا 6 از 6

نام تاپیک: عدم نمایش دیتا گرید

  1. #1
    کاربر دائمی
    تاریخ عضویت
    شهریور 1382
    محل زندگی
    عالم ماده
    پست
    977

    عدم نمایش دیتا گرید

    با کد زیر پیغام خطایی نمی دهد اما اصلا دیتاگ ریدی نمایش نمی دهد.
    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    SqlConnection conn = new
    SqlConnection("server=(local);uid=sa;p wd=yaali;database=MDB" );
    //if(!Page.IsPostBack){
    // BindGrid();
    SqlDataAdapter myCommand = new SqlDataAdapter("SELECT * FROM tblPrimary", conn);

    DataSet ds = new DataSet();
    myCommand.Fill(ds,"tblPrimary");
    DataView dv= ds.Tables["tblPrimary"].DefaultView;
    dv.Sort="id";

    MyDataGrid.DataSource=dv;
    MyDataGrid.DataBind();

    }

  2. #2
    کاربر دائمی
    تاریخ عضویت
    بهمن 1381
    محل زندگی
    ایران - تهران
    پست
    2,342
    DataView را فراموش نکرده ای؟

  3. #3
    کاربر دائمی
    تاریخ عضویت
    شهریور 1382
    محل زندگی
    عالم ماده
    پست
    977
    در فصل 8 جزوه شما برای نمایش داده در دیتا گرید از دیتا ویو استفاده نکرده اید ،فقط در مثالی که سورت را انجام می دهد دیتا ویو هست اصلا این کد مشکلی دارد؟
    public void BindGrid() 
    {
    SqlConnection conn = new SqlConnection(
    "server=(local);uid=sa;pwd=yaali;database= MDB");
    SqlDataAdapter myCommand = new SqlDataAdapter("SELECT * FROM tblPrimary", conn);

    DataSet ds = new DataSet();
    myCommand.Fill(ds);
    MyDataGrid.DataSource=ds.Tables["tblPrimary"&# 93;.DefaultView;
    MyDataGrid.DataBind();
    }

  4. #4
    کاربر دائمی
    تاریخ عضویت
    شهریور 1382
    محل زندگی
    عالم ماده
    پست
    977
    جناب نصیری این مثال خود مایکروسافته!
    <script language="C#‎" runat="server">
    SqlConnection myConnection;

    protected void Page_Load(Object Src, EventArgs E)
    {
    // Create a connection to the "pubs" SQL database located on the
    // local computer.
    myConnection = new SqlConnection ("server=localhost;uid=sa;pwd=yaali;" +
    "database=pubs;Trusted_Connection=Yes");
    // Determine whether the page is a postback. If it is not a
    // postback, call BindGrid.
    if (!IsPostBack) BindGrid();
    }
    // Create an index to the DataGrid row that is clicked and
    // call BindGrid.
    public void MyDataGrid_Edit(Object sender, DataGridCommandEventArgs E)
    {
    MyDataGrid.EditItemIndex = (int)E.Item.ItemIndex;
    BindGrid();
    }

    // Cancel resets the index to the row's previous settings.
    public void MyDataGrid_Cancel(Object sender,
    DataGridCommandEventArgs E)
    {
    MyDataGrid.EditItemIndex = -1;
    BindGrid();
    }
    // When the Update link is clicked, build a SQL UPDATE command,
    // connect to the database, update the row's information in the
    // database, and rebind the DataGrid to show the updated information.
    public void MyDataGrid_Update(Object sender,
    DataGridCommandEventArgs E)
    {
    String updateCmd = "UPDATE Authors SET au_id = @Id," +
    " au_lname = @LName, au_fname = @FName, phone = @Phone," +
    " address = @Address, city = @City, state = @State," +
    " zip = @Zip, contract = @Contract WHERE au_id = @Id;";
    SqlCommand myCommand = new SqlCommand(updateCmd, myConnection);
    myCommand.Parameters.Add(new SqlParameter("@Id",
    SqlDbType.VarChar));
    myCommand.Parameters.Add(new SqlParameter("@LName",
    SqlDbType.VarChar));
    myCommand.Parameters.Add(new SqlParameter("@FName",
    SqlDbType.VarChar));
    myCommand.Parameters.Add(new SqlParameter("@Phone",
    SqlDbType.VarChar));
    myCommand.Parameters.Add(new SqlParameter("@Address",
    SqlDbType.VarChar));
    myCommand.Parameters.Add(new SqlParameter("@City",
    SqlDbType.VarChar));
    myCommand.Parameters.Add(new SqlParameter("@State",
    SqlDbType.VarChar));
    myCommand.Parameters.Add(new SqlParameter("@Zip",
    SqlDbType.VarChar));
    myCommand.Parameters.Add(new SqlParameter("@Contract",
    SqlDbType.VarChar));
    // Initialize the SqlCommand "@Id" parameter to the ID of the
    // row that must be clicked.
    myCommand.Parameters["@Id"].Value =
    MyDataGrid.DataKeys[(int)E.Item.ItemIn dex];
    // Create an array of column names.
    String[] cols = {"@Id","@LName","@FName","@Phone",
    "@Address", "@City","@State","@Zip","@Contract"};
    // Iterate through the columns, checking for empty values.
    // Skip the first, second, and last columns. If an empty value
    // is found, display an error message box. Also initialize the
    // SqlCommand parameter values.
    int numCols = E.Item.Cells.Count;
    for (int i=2; i<numCols-1; i++)
    {
    String colvalue = ((TextBox)E.Item.Cells[i].Cont rols[0]).Text;
    if (i<6 && colvalue == "")
    {
    Message.InnerHtml = "ERROR: Null values not allowed for" +
    " Author ID, Name or Phone";
    Message.Style["color"] = "red";
    return;
    }
    myCommand.Parameters[cols[i-1]].Value = colvalue;
    }
    // Append the last field, converting true/false values to 0/1.
    if (String.Compare(((TextBox)E.It em.Cells
    [numCols-1].Controls[0]).Text, "true", true)==0)
    myCommand.Parameters["@Contract"].Value = "1";
    else
    myCommand.Parameters["@Contract"].Value = "0";
    // Connect to the database and update the information.
    myCommand.Connection.Open();
    // Test whether the data was updated and display the
    //appropriate message to the user.
    try
    {
    myCommand.ExecuteNonQuery();
    Message.InnerHtml = "<b>Record Updated.</b><br>";
    MyDataGrid.EditItemIndex = -1;
    }
    catch (SqlException e)
    {
    if (e.Number == 2627)
    Message.InnerHtml = "ERROR: A record already exists" +
    " with the same primary key";
    else
    Message.InnerHtml = "ERROR: Could not update record," +
    " please ensure the fields are correctly filled out";
    Message.Style["color"] = "red";
    }
    // Close the connection.
    myCommand.Connection.Close();
    // Show the updated information.
    BindGrid();
    }

    // The BindGrid procedure connects to the database and implements
    // a SQL SELECT query to get all data in the "Authors" table.
    public void BindGrid()
    {
    SqlConnection myConnection = new SqlConnection(
    "server=localhost;uid=sa;pwd=yaali;database=pubs;T rusted_Connection=Yes");
    SqlDataAdapter myCommand = new SqlDataAdapter(
    "SELECT * FROM authors", myConnection);
    DataSet ds = new DataSet();
    myCommand.Fill(ds);
    MyDataGrid.DataSource=ds;
    MyDataGrid.DataBind();

    من هم کپی کرده و تغییراتی بسیار جزیی دادم اما تنها صفحه ای خالی بدون پیغام خطا را نمایش میدهد!

  5. #5
    کاربر دائمی
    تاریخ عضویت
    بهمن 1381
    محل زندگی
    ایران - تهران
    پست
    2,342
    یک سری آدرس مقاله در مورد دیتاگرید اینجا هست:
    http://www.barnamenevis.org/viewtopic.php?t=2346
    فکر کنم برای 6 ماه کافی باشد. :wink:

  6. #6
    کاربر دائمی
    تاریخ عضویت
    شهریور 1382
    محل زندگی
    عالم ماده
    پست
    977
    جناب نصیری خودمونیما حوصله که نداشته باشین به نخود سیاه حواله می دهید :lol:
    باشه!

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •