Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to select fist cell of a row where it is written id I can easy take it with this code first time.
C#
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);
}

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.NET
<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>



C#
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);
    
            }
Posted
Updated 25-Jun-16 8:53am
v3
Comments
I don't understand. Where is the issue exactly?
Member 12603626 25-Jun-16 15:39pm    
If I use button1 the label text who is ControlParameter will change and gidview will have different data and I whant when I press select on this new gridview to select id form row selected who it is in cell1, but the aspx.net give me id for gridviw who wasent change on button

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900