title: GridView's DataSource in Code Behind
body: <p>I have already a populated <code>GridView</code> working perfect, But now I need to set some <code>parameters</code>. I'm populating the <code>gridview</code> in <code>HTML page</code>. Here's my <code>FULL GridView HTML code</code>
  Hope you guys don't consider it as an spam, because its a huge code.</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" style="font-family: Verdana, Arial, Sans-Serif" 
              DataKeyNames="id"
              CssClass="gridview" DataSourceID="MyDataSource"
              AllowSorting ="True" AllowPaging="True" BackColor="#CCCCCC" 
              BorderStyle="Inset" BorderWidth="2px" BorderColor="GrayText"
              CellPadding="1"
              CellSpacing="5"
              HeaderStyle-HorizontalAlign="Center"
              OnRowDataBound="GridView1_RowDataBound" 
              ForeColor = "Black" RowStyle-CssClass="gridview" 
              onrowcommand="GridView1_RowCommand"&gt;            
              &lt;AlternatingRowStyle BackColor="#CCCCCC" /&gt;
                  &lt;columns&gt;
  
                      &lt;asp:BoundField HeaderText="ID" DataField="id"  /&gt;
                      &lt;asp:BoundField HeaderText="PRIORIDADE" DataField="prioridade" SortExpression="prioridade" ItemStyle-HorizontalAlign="Center" /&gt;
                      &lt;asp:BoundField  HeaderText="SITUAÇÃO"  DataField="situacao" SortExpression="situacao" ItemStyle-HorizontalAlign="Center" &gt;
                      &lt;ItemStyle HorizontalAlign="Center" /&gt;
                      &lt;/asp:BoundField&gt;
                      &lt;asp:BoundField HeaderText="RESPONSAVEL" DataField="responsavel" SortExpression="responsavel" HeaderStyle-Width="65px" ItemStyle-HorizontalAlign="Center"&gt;
                      &lt;HeaderStyle Width="65px" /&gt;
                      &lt;ItemStyle HorizontalAlign="Center" /&gt;
                      &lt;/asp:BoundField&gt;
                      &lt;asp:BoundField HeaderText="DATA DE CADASTRO" DataField="dt_cadastro" DataFormatString="{0:dd/MM/yyyy}" HeaderStyle-Width="60px"
                      SortExpression="dt_cadastro" ItemStyle-HorizontalAlign="Center" &gt;
                      &lt;HeaderStyle Width="60px" /&gt;
                      &lt;ItemStyle HorizontalAlign="Center" /&gt;
                      &lt;/asp:BoundField&gt;
                      &lt;asp:BoundField HeaderText="PREVISÃO DE TÉRMINO" DataField="previsao_termino" DataFormatString="{0:dd/MM/yyyy}" HeaderStyle-Width="60px"
                      SortExpression="previsao_termino" ItemStyle-HorizontalAlign="Center"&gt;
                      &lt;HeaderStyle Width="60px" /&gt;
                      &lt;ItemStyle HorizontalAlign="Center" /&gt;
                      &lt;/asp:BoundField&gt;
                      &lt;asp:BoundField HeaderText="PROJETO" DataField="projeto"  ItemStyle-HorizontalAlign="Center"&gt;&lt;/asp:BoundField&gt;
                      &lt;asp:BoundField HeaderText="FUNCIONALIDADE" DataField="funcionalidade" ItemStyle-HorizontalAlign="Center" /&gt;
                      &lt;asp:BoundField HeaderText="CLUBE" DataField="clube" SortExpression="clube" ItemStyle-HorizontalAlign="Center" /&gt;
  
                      &lt;asp:TemplateField HeaderStyle-Width="70px" HeaderText="VISUALIZAR" &gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Button ID="Btn_Visualizar" runat="server" Text="VISUALIZAR" CssClass="Btn_Grid"  Font-Size="7pt" Font-Names="Verdana, Arial"
                              CommandName="visualizar" CommandArgument="&lt;%# ((GridViewRow)Container).RowIndex %&gt;" /&gt;                            
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField HeaderStyle-Width="66px" HeaderText="ALTERAR"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Button ID="Btn_Alterar" runat="server" Text="ALTERAR" CssClass="Btn_Grid" Font-Size="7pt" Font-Names="Verdana, Arial"
                              CommandName="editar" CommandArgument="&lt;%# ((GridViewRow)Container).RowIndex %&gt;" /&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
  
  
                  &lt;/columns&gt;
              &lt;EditRowStyle ForeColor="Black" CssClass="GridViewEditRow" /&gt;
              &lt;FooterStyle BackColor="#CCCCCC" /&gt;
              &lt;HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" BorderColor="White" BorderStyle="Solid" BorderWidth="1px" /&gt;
              &lt;PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" /&gt;
              &lt;RowStyle BackColor="White" /&gt;
              &lt;SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /&gt;      
              &lt;/asp:GridView&gt;           
  
              &lt;asp:SqlDataSource ID="MyDataSource" runat="server"
                 ConnectionString="server=localhost;User Id=xx;password=xxxx;database=xxxx"
                 ProviderName ="MySql.Data.MySqlClient"
  
                 SelectCommand="SELECT ch.id, sit.descricao as situacao, resp.responsavel, ch.dt_cadastro, ch.previsao_termino, func.descricao as funcionalidade, 
                                proj.descricao as projeto ,pr.id as prid, pr.prioridade, clb.clube
                                FROM chamados AS ch  
                                INNER JOIN prioridades as pr  ON ch.prioridade = pr.id
                                INNER JOIN clubes as clb ON ch.clube = clb.id 
                                INNER JOIN responsaveis as resp ON ch.responsavel = resp.id
                                INNER JOIN situacoes as sit ON ch.situacao = sit.id 
                                INNER JOIN projetos as proj ON ch.projeto = proj.id
                                INNER JOIN funcionalidades as func ON ch.funcionalidade = func.id WHERE situacao != 3"
  
                 UpdateCommand="Update chamados SET status = @status , responsavel = @responsavel, 
                 previsao_termino = @previsao_termino, titulo = @titulo WHERE id = @id"
  
                 DeleteCommand="Delete FROM chamados WHERE id = @id"&gt;
                 &lt;DeleteParameters&gt;
                              &lt;asp:Parameter Name="id" Type="Int32" /&gt;
  
                 &lt;/DeleteParameters&gt;
  
                 &lt;UpdateParameters&gt;
                              &lt;asp:Parameter Name="status" Type="String" /&gt;
                              &lt;asp:Parameter Name="responsavel" Type="String" /&gt;
                              &lt;asp:Parameter Name="previsao_termino" Type="DateTime" /&gt;
                              &lt;asp:Parameter Name="titulo" Type="String" /&gt;
                              &lt;asp:Parameter Name="id" Type="Int32" /&gt;
                 &lt;/UpdateParameters&gt;
              &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>How may I do all of this in <code>Aspx.cs</code> file, do I create a DataSet and set as DataSource to the GridView , and How I set the values to the columns ? Thanks !
  Obs: I Also have two butons on the cells.
  [Comment] - Other solution would be pass a <code>parameter</code>in the code below, is it possible ? I need to pass the value of a <code>Session</code></p>