2

Good day guys, I am binding asp.net gridview whose datasource table is a programatically created table which gets populated dynamically by getting data from different tables via joins, I want to edit it, how come I am going to get row index(for editing) as data is coming from different tables And has no unique identifier as it is just in memory i.e. dataset visualiser, neither hidden field nor datakeynames seems to work, any help please?

4
  • 1
    Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. Commented Jan 19, 2017 at 7:33
  • When you get data from multiple tables add uniqueidentifier column, and set Guid.NewGuid() value for each row, and then you will have unique column Commented Jan 19, 2017 at 7:46
  • @un-lucky I have bolded my exact problem, thanks for pointing it out Commented Jan 19, 2017 at 8:33
  • @IkramTurgunbaev let me try it please Commented Jan 19, 2017 at 8:40

1 Answer 1

2
DataTable GetTableWithUniqueColumn()
        {
            DataTable table = new DataTable();
            table = GetDataFromDB(); //  dynamically getting data from different tables via joins
            table.Columns.Add("UniqueColumn", typeof(Guid));
            foreach (DataRow row in table.Rows)
            {
                row["UniqueColumn"] = Guid.NewGuid();
            }

            return table;
        }
Sign up to request clarification or add additional context in comments.

9 Comments

That has of course answered my question, now I can identify each row in Programatically Created DataTable uniquely. On the other hand I was displaying this table in gridview, which has started showing 'UniqueColumn' too, any idea to hide it please.
After binding datatable to grid datasource this code will hide column gridview1.Columns["UniqueColumn"].Visible = false;
I tried this already and once again after you specified but intellisense says that it will not accept gridview1.Columns["some string here"].Visible=false; Its needs [int], Anyway to let it accept string because index lets just say can't be determined in advance.
Sorry, you're right, gridview1.Colums[] waits int index of column. There is other way hiding column by its header name foreach (DataControlField col in gridReviews.Columns) { if (col.HeaderText == "Name") { col.Visible = false; } } try this
Also it looks like gridview1.Columns[int].Visible=false works only for server controls like item template or bound field columns, in my case it is hiding item template column but not dynamically created columns,
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.