如何在运行时更改datagrid

如何在运行时更改datagrid

本文介绍了如何在运行时更改datagrid的列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



这是我的存储过程。

Hi friends,

This is my storedprocedure.

ALTER procedure [dbo].[sp_getmarkforclass](@classid int,@examname varchar(30))
as
begin
declare @paramlist varchar(max),@query nvarchar(max),@examid int
select @examid=ExamId from ExamNameSetting_details where ExamName=@examname
set @paramlist=STUFF((select distinct ',[' + SubjectId + ']' from School.dbo.Mark_details where classid=@classid and ExamId=@examid for xml path('')),1,1,'')
set @query=N'select * from(select sc.RollNumber,sa.StudnetAdmissionNumber,sb.StudentName,sa.SubjectId,sa.MarkObtained from School.dbo.Mark_details sa inner join School.dbo.StudentAdmission_details sb on sa.StudnetAdmissionNumber=sb.AdmissionNumber inner join StudentRollNumberAllocation_details sc on sb.AdmissionNumber=sc.AdmissionNumber ) p PIVOT(Max(MarkObtained)for SubjectId IN ('+@paramlist+')) AS pvt'
execute(@query)
end







这是我的输出






and this is my output

RollNumber	adnumberStudentName	23011	23012	23013	23014	23015
12130100	103	divya	        77      88      77	77	66
12130101	102	Gayathiri	77	88	99	99	77
12130102	100	Chandru		77	88	99	88      88





我想要那个列表标题为泰米尔语为23011,英语为23012,数学为23013,同样如此。这个23011和以下是泰米尔语主题名的主题,并在主题名表上。如何在加载到datagrid时更改columnName。



and I want that columnheader as Tamil for 23011, english for23012, maths for 23013 and likewise. this 23011 and follows are subjectid for subjectname of tamil and follows on the subjectname table. how can change the columnName when load to datagrid.

推荐答案

protected void gdvUsuarios_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
           if(e.Row.Cells[3].Text == "23011")
                e.Row.Cells[3].Text = "Tamil";
           if(e.Row.Cells[4].Text == "23012")
                e.Row.Cells[4].Text = "english";
           if(e.Row.Cells[5].Text == "23013")
                e.Row.Cells[5].Text = "maths";
           if(e.Row.Cells[6].Text == "23014")
                e.Row.Cells[6].Text = "Geography";
           if(e.Row.Cells[7].Text == "23015")
                e.Row.Cells[7].Text = "History";
        }
    }


这篇关于如何在运行时更改datagrid的列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 18:09