选择gridview的单元格,该单元格在执行期间会多次更改数据源 [英] Selected a cell of a gridview that that change several times the data source during execution

查看:81
本文介绍了选择gridview的单元格,该单元格在执行期间会多次更改数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择写入id的行的第一个单元格我可以第一次使用此代码轻松获取它。

I want to select fist cell of a row where it is written id I can easy take it with this code first time.

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    GridView1.DataBind();
    GridViewRow row = GridView1.SelectedRow;
    string strCell = row.Cells[1].Text;
    string myPageUrl = "Meci.aspx?ID=" + strCell;
    Response.Redirect(myPageUrl);
}



但我有一个标签,它写的是当前日期,它是gridview数据源的ControlParameter,当你从另一个标签中选择一个日期时,并点击它在该日期更改的按钮标签文本,如果我想要从gridview中选择带有新数据的id时更改此标签,我的方法选择第一个gridview的id或者给出错误Index is out of of当新gridview有更多行然后是第一个时,范围。如何修改我的代码,以便在日期更改时选择此ID?



我尝试了什么:




But I have a label where it is write the current date and it is ControlParameter for datasource of gridview, and when you select a date from another label, and click on a button label text it is changed in that date, if I change this label when I want to select id from the gridview with new data, my method select the id of the first gridview or give the error Index was out of range when new gridview have more rows then the first one. how can I modify my code to be able to select this ID when the date changes?

What I have tried:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Conexiune %>" SelectCommand="SELECT  Meci.Id_meci, Campionat.Campionat, Campionat.Editia, Meci.Etapa, Meci.Gazda, Meci.Scor, Meci.Oaspete, Meci.Ora FROM Meci INNER JOIN Campionat ON Meci.Id_campionat = Campionat.Id_campionat WHERE (Meci.Data = @data) ORDER BY Campionat.Campionat, Campionat.Editia, Meci.Ora, Meci.Gazda">
        <SelectParameters>
            <asp:ControlParameter ControlID="Label1" Name="data" PropertyName="Text"  />
        </SelectParameters>
    </asp:SqlDataSource>










protected void Page_Load(object sender, EventArgs e)
    
            {string data;
            data = Convert.ToString(DateTime.Today.Year) + "-0" + Convert.ToString(DateTime.UtcNow.Month) + "-" + Convert.ToString(DateTime.UtcNow.Day);
            string luna = Convert.ToString(DateTime.UtcNow.Month);
            if (luna == "10")
                 data = Convert.ToString( DateTime.Today.Year)+"-"+ Convert.ToString( DateTime.UtcNow.Month )+"-"+  Convert.ToString( DateTime.UtcNow.Day);
            if (luna == "11")
                data = Convert.ToString(DateTime.Today.Year) + "-" + Convert.ToString(DateTime.UtcNow.Month) + "-" + Convert.ToString(DateTime.UtcNow.Day);
            if (luna == "12")
                    data = Convert.ToString(DateTime.Today.Year) + "-" + Convert.ToString(DateTime.UtcNow.Month) + "-" + Convert.ToString(DateTime.UtcNow.Day);
               
                 
                Label1.Text = data;
                GridView1.DataBind();
            }
    
           
    
            protected void Button1_Click(object sender, EventArgs e)
            {
    
                Label1.Text = T_data.Text;
                GridView1.DataBind();
            }
    
            protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
            {
                GridView1.DataBind();
                GridViewRow row = GridView1.SelectedRow;
                string strCell = row.Cells[1].Text;
                string myPageUrl = "Meci.aspx?ID=" + strCell;
                Response.Redirect(myPageUrl);
    
            }

推荐答案

ConnectionStrings:Conexiune%> SelectCommand = SELECT Meci.Id_meci,Campionat.Campionat,Campionat.Editia,Meci.Etapa,Meci.Gazda,Meci.Scor,Meci.Oaspete,Meci.Ora来自Meci INNER JOIN Campionat ON Meci.Id_campionat = Campionat.Id_campionat WHERE(Meci.Data = @data)ORDER BY Campionat.Campionat,Campionat.Editia,Meci.Ora,Meci.Gazda >
< SelectParameters >
< asp:ControlParameter ControlID = Label1 名称 = data PropertyName = 文字 / >
< span class =code-keyword>< / SelectParameters >
< / asp:SqlDataSource >
ConnectionStrings:Conexiune %>" SelectCommand="SELECT Meci.Id_meci, Campionat.Campionat, Campionat.Editia, Meci.Etapa, Meci.Gazda, Meci.Scor, Meci.Oaspete, Meci.Ora FROM Meci INNER JOIN Campionat ON Meci.Id_campionat = Campionat.Id_campionat WHERE (Meci.Data = @data) ORDER BY Campionat.Campionat, Campionat.Editia, Meci.Ora, Meci.Gazda"> <SelectParameters> <asp:ControlParameter ControlID="Label1" Name="data" PropertyName="Text" /> </SelectParameters> </asp:SqlDataSource>










protected void Page_Load(object sender, EventArgs e)
    
            {string data;
            data = Convert.ToString(DateTime.Today.Year) + "-0" + Convert.ToString(DateTime.UtcNow.Month) + "-" + Convert.ToString(DateTime.UtcNow.Day);
            string luna = Convert.ToString(DateTime.UtcNow.Month);
            if (luna == "10")
                 data = Convert.ToString( DateTime.Today.Year)+"-"+ Convert.ToString( DateTime.UtcNow.Month )+"-"+  Convert.ToString( DateTime.UtcNow.Day);
            if (luna == "11")
                data = Convert.ToString(DateTime.Today.Year) + "-" + Convert.ToString(DateTime.UtcNow.Month) + "-" + Convert.ToString(DateTime.UtcNow.Day);
            if (luna == "12")
                    data = Convert.ToString(DateTime.Today.Year) + "-" + Convert.ToString(DateTime.UtcNow.Month) + "-" + Convert.ToString(DateTime.UtcNow.Day);
               
                 
                Label1.Text = data;
                GridView1.DataBind();
            }
    
           
    
            protected void Button1_Click(object sender, EventArgs e)
            {
    
                Label1.Text = T_data.Text;
                GridView1.DataBind();
            }
    
            protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
            {
                GridView1.DataBind();
                GridViewRow row = GridView1.SelectedRow;
                string strCell = row.Cells[1].Text;
                string myPageUrl = "Meci.aspx?ID=" + strCell;
                Response.Redirect(myPageUrl);
    
            }


这篇关于选择gridview的单元格,该单元格在执行期间会多次更改数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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