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);
}
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);
}