Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0 && comboBox2.SelectedIndex == 9)
            {
                SqlCommand cm1 = new SqlCommand("select * from traintime", con);
                DataTable dth = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cm1);
                da.Fill(dth);
                dataGridView2.DataSource = dth;
            }
            else if (comboBox1.SelectedIndex == 0 && comboBox2.SelectedIndex == 2)
            {
                SqlCommand cm1 = new SqlCommand("select * from traintime where TrainNo=11026", con);
                DataTable dth = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cm1);
                da.Fill(dth);
                dataGridView2.DataSource = dth;
            }
Posted
Updated 28-Jan-14 9:24am
v2
Comments
Abhinav Chaudhary 29-Jan-14 0:18am    
I want to give links to the table values....I want to give different tables links to these datagridview values...Please help!
OPees 29-Jan-14 6:23am    
Means?
DipsMak 29-Jan-14 7:42am    
make use of item templates in your gridview and put link buttons in it..then bind the gridview
Abhinav Chaudhary 30-Jan-14 1:34am    
where is item template..?...actually i want to give links of tables to each value of datagridview table...

1 solution

XML
Use gridview like this, in place of label you can use link button.....


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id1" DataSourceID="ObjectDataSource1">
<Columns>
        <asp:TemplateField HeaderText="Name" SortExpression="FirstName">
           <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
            </ItemTemplate>
          </asp:TemplateField>
    </asp:TemplateField>
</Columns>
</asp:GridView>
 
Share this answer
 
Comments
Abhinav Chaudhary 31-Jan-14 11:33am    
can you post it for windows form application,please?....and thanks for that solution.

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