如何使用asp.net保存数据表中的dropdownlist选择值 [英] how to save dropdownlist selected value in datatable using asp.net

查看:103
本文介绍了如何使用asp.net保存数据表中的dropdownlist选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设计如下





学生ID下拉列表1

学生姓名Dropdownlist2

课程下拉列表3





一个保存按钮,选择drodpdownlist项目,选择要保存在数据表中的项目。

在运行模式下,当我从下拉列表中选择上面的studentid,studnetname和course并点击保存按钮





i希望将选定的下拉列表项保存到数据表中。





我怎么能用csharp。

请帮帮我。





问候,

Narasiman P.

Design as follows


Student id Dropdownlist1
Student Name Dropdownlist2
Course Dropdownlist3


And one save button, when iselect the drodpdownlist item that selected item to be save in datatable.
in the run mode when i select the above studentid,studnetname and course from the dropdownlist and click the save button


i want to save the selected dropdownlist item into datatable.


for that how can i do using csharp.
please help me.


Regards,
Narasiman P.

推荐答案

从DropDown列表中获取价值......

To Get Value From DropDown List...
string StudentId = Dropdownlist1.SelectedItem.Text.ToString();
string StudentName = Dropdownlist2.SelectedItem.Text.ToString();
string Cource = Dropdownlist3.SelectedItem.Text.ToString();
InsertCategory(StudentId,StudentName,Course);





将此参数传递给DAL方法...



Pass This Arguments to Your DAL Method...

public int InsertCategory(string StudentId, string StudentName, string Course)
    {
        string connstr = ConfigurationManager.ConnectionStrings["CONNSTRING"].ConnectionString;    //connection string
        conn = new SqlConnection(connstr);  //developed connection for specific database by passing connectionstring
        SqlCommand cmd = new SqlCommand();
        
        try
        {
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }

            cmd.CommandText = "InsertStoredProcedure";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = conn;

            cmd.Parameters.Add(new SqlParameter("@StudentID", StudentID));
            cmd.Parameters.Add(new SqlParameter("@StudentName", StudentName));
            cmd.Parameters.Add(new SqlParameter("@Course", Course));
            
            int result = 0;
            result = cmd.ExecuteNonQuery();

            return result;
        }
        catch (Exception ex)
        {
            Console.Write("error in inserting : " + ex.Message + " inner exceptin : " + ex.InnerException);
            return 0;
        }
        finally
        {
            cmd.Dispose();
            conn.Close();
        }

    }





希望这有助于

- --------------

Pratik Bhuva



Hope This Helps
----------------
Pratik Bhuva


你可以使用dropdown1.SelectedItem.Value保存下拉列表的值并保存下拉文本使用dropdown1.SelectedItem.Text
you can save value of dropdown using dropdown1.SelectedItem.Value and also save dropdown text using dropdown1.SelectedItem.Text


这篇关于如何使用asp.net保存数据表中的dropdownlist选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆