INTERVIEW QUESTIONS
MICROSOFT
ASP.NET 2.0
DETAILS
Question: How to get the cell value on which we click on Data Grid and how can we high light the clicked area of data grid with some color? i.e. for example in Datagrid1 emp details records(empid,empname,empsal...) are dispalyed if we click on one record how to get that empid,empname values and how to highlight that clicked cell with some colour?
Answer: This is a Code you may try: forgetting the value in cell. Try sqlconn.Open() MyAdapter = New SqlDataAdapter(showquery, sqlconn) Ds = New DataSet MyAdapter.Fill(Ds) Dim s As Integer = Ds.Tables(0).Rows.Count If Ds.Tables(0).Rows.Count > 0 Then orderno = DataGridView1.Item(1, 0).Value invoiceno1 = DataGridView1.Item(0, 0).Value End If Catch ex As Exception 'MsgBox(ex.Message) Finally sqlconn.Close() End Try
|
Question:
How to get the cell value on which we click on Data Grid and how can we high light the clicked area of data grid with some color? i.e. for example in Datagrid1 emp details records(empid,empname,empsal...) are dispalyed if we click on one record how to get that empid,empname values and how to highlight that clicked cell with some colour?
Answer:
This is a Code you may try: forgetting the value in cell. Try sqlconn.Open() MyAdapter = New SqlDataAdapter(showquery, sqlconn) Ds = New DataSet MyAdapter.Fill(Ds) Dim s As Integer = Ds.Tables(0).Rows.Count If Ds.Tables(0).Rows.Count > 0 Then orderno = DataGridView1.Item(1, 0).Value invoiceno1 = DataGridView1.Item(0, 0).Value End If Catch ex As Exception 'MsgBox(ex.Message) Finally sqlconn.Close() End Try Source: CoolInterview.com
Answered by: santosh kumar sahu | Date: 2/8/2008
| Contact santosh kumar sahu
In the databound event of data grid
for(i=0;i<e.row.cells.count;i++) { e.row.cells[i].attributes.add("onclick","this.backcolor='#ff0000'"); } Source: CoolInterview.com
Answered by: N V R Reddy | Date: 3/7/2008
| Contact N V R Reddy
protected void Page_Load(object sender, EventArgs e) { string con = "Database=DataBaseName;Server=serverName;UserId=yourId;password=yourpwd;"; SqlConnection sCon = new SqlConnection(con); SqlCommand cmd = new SqlCommand(); cmd.Connection = sCon; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "[EmpDetails_select]"; SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind();
} protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { int iIndex = GridView1.SelectedIndex; GridView1.Rows[iIndex].BackColor = System.Drawing.Color.Pink; string EmpId = GridView1.Rows[iIndex].Cells[1].Text.Trim(); Response.Write("EMPID:" +EmpId+ ", "); string EmpName = GridView1.Rows[iIndex].Cells[2].Text.Trim(); Response.Write("EMPName:" + EmpName + " ");
} Source: CoolInterview.com
Answered by: Vasavi Polisetty | Date: 4/21/2008
| Contact Vasavi Polisetty
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|