如何迭代使用转发器?

时间:2014-02-26 07:35:37

标签: c#

我有一个转发器显示puja.i的列表也使用了一个datalist来显示temple的名称。每当我点击搜索它只显示转发器的最后一个值,即它只取最后一个值转发器....我的问题是如何在转发器内使用循环??? 这是我使用datalist和repeater后面的代码:

protected void Page_Load(object sender, EventArgs e)
    {

        //lblnodatafound.Visible = true;
        //lbldatafound.Visible = false;
        if (Request.QueryString["search"] != null)
        {
            var dt = new DataTable("Data");
            String source = Request.QueryString["search"];
            var splitseparator = new string[] { " " };
            String[] result = source.Split(splitseparator, StringSplitOptions.RemoveEmptyEntries);

            foreach (String s in result)
            {
                if (IsAlphaNumeric(s) == true)
                {
                    var dttemp = new DataTable();
                    dttemp = fnsearch(s);
                    dt.Merge(dttemp, true);
                }
            }
            if (dt.Rows.Count != 0)
            {


                    int count = dt.Rows.Count;
                    if (dt.Rows.Count > 0)
                    {
                        DataList1.DataSource = dt;
                        DataList1.DataBind();

                        lblnodatafound.Visible = false;
                        lbldatafound.Visible = true;
        //added the repeater to display the list of puja

                            for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            String id = dt.Rows[i]["id"].ToString();
                            string query = "select puja.id,puja.name as puja_name, mandir.name as mandir_name from puja,mandir where mandir.id= puja.with_mandir and puja.with_mandir = '" + id + "'";
                            conn.Open();
                            MySqlCommand cmd = new MySqlCommand(query, conn);
                            MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
                            DataTable dt1 = new DataTable();
                            adp.Fill(dt1);
                            conn.Close();


                                if (dt1.Rows.Count > 0)
                                {
                                    lblmandirpuja.Text = "Poja in " + dt1.Rows[0]["mandir_name"];
                                    foreach (RepeaterItem repeatItem in Repeater1.Items){

                                    Repeater1.DataSource = dt1;

                                    Repeater1.DataBind();
                                        }

                                }

                        }
                    }
                    }
                    else
                    {
                        lblnodatafound.Visible = true;
                        lbldatafound.Visible=false;

                    }

        }
        }

1 个答案:

答案 0 :(得分:0)

尝试更改此行:

if (dt1.Rows.Count > 0)

类似于:

for(int i = 0; i < dt1.Rows.Count; i++)

这一个:

lblmandirpuja.Text = "Poja in " + dt1.Rows[0]["mandir_name"];

i为0:

lblmandirpuja.Text = "Poja in " + dt1.Rows[i]["mandir_name"];