Click here to Skip to main content
15,885,890 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi how can i a Button column to a Datagrid programatically. I want to do this through code in codebehind file.

Also i want to selectively enable or disable this button based on record (If status is Reported then Enable it else disable this button,else status is Sent then Disable this button
This is the code am tried and it shows all the datacolumn as enabled,how to disable status shows Sent.
C#
int rowIndex = 10;
var rowData = dataGrid1.Items[rowIndex] as DataRowView;
rowData["LinkRPT"] = "";
dataGrid1.Columns[10].Visibility = Visibility.Visible;
SqlConnection con = new SqlConnection("Data Source=WINCTRL-TNT3FMR\\SQLEXPRESS;Initial    
            Catalog=Roamani;Integrated Security=True");
if (dataGrid1.SelectedItems.Count > 0)
{
    for (int i = 0; i < dataGrid1.SelectedItems.Count; i++)
    {
        System.Data.DataRowView selectedFile= (System.Data.DataRowView)dataGrid1.SelectedItem;//Row is detected and stored in selectedfile object
        string str = Convert.ToString(selectedFile.Row.ItemArray[10]);
        string sts = Convert.ToString(selectedFile.Row.ItemArray[9]);

        string query = "SELECT Report FROM StudyTable WHERE StudyUID='" + str + "' AND status='3'";
        SqlCommand cmd = new SqlCommand(query, con);
        con.Open();
        SqlDataReader rdr = cmd.ExecuteReader();
        try
        {
            while (rdr.Read())
            {
                query = rdr.GetString(0);
                //dataGrid1.Columns[10] = query;
                OpenReport(query);
            }
        }
        catch (Exception ex)
        {
            ReallySimpleLog.ReallySimpleLog.WriteLog(ex);
        }
    }
}
con.Close();
Posted
Updated 16-Jun-14 22:56pm
v2
Comments
ZurdoDev 18-Jun-14 13:59pm    
Where are you stuck? I don't understand.

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