我想使用Design ..更改gridview的标题文本。
<asp:BoundField HeaderText="">
我在javascript中创建了一个变量并在条件下初始化变量防御然后我试着在这里调用该变量,如下所示:
<asp:BoundField HeaderText="Text Here" DataField="slno" >
我在这里使用&#34;文字&#34;存储在一个可变名称中的字符串。我想使用那个变量
我的代码:
<script type="text/javascript" language="javascript">
/// <summary>
/// TO ACCESS COOKIE VARIABLE
/// </summary>
var flag;
var ca = document.cookie.split('=');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ',') c = c.substring(1);
}
if (c != '' && c != null) {
flag = c;
}
else {
flag = 1;
}
//*********************************************
if (flag == 1) {
var name_lbl = "Hai";
}
else if (flag == 2) {
var name_lbl = "How are you?";
}
</script>
//------------------------------------------------
</asp:Content>
<form id="form1" runat="server">
</table>
<div style="overflow: auto; height: 99%;" id="divTable">
<table><tr><td>
<label for='field ID'> <b><input type="text" id="kilist_lbl" size="20" style="border: none; height:20px" readonly/></b> </label> <br />
</td></tr></table>
<asp:GridView ID="gvareadetails" runat="server"
CssClass="mGrid" AutoGenerateColumns="False">
<Columns>
<%-- here is the problem when assigning ID to headerText label --%>
<asp:BoundField HeaderText='sss' DataField="slno" >
<ItemStyle Width="5%" />
</asp:BoundField>
</Columns>
</asp:GridView>
</div>
</form>
<script type="text/javascript" language="javascript">
document.getElementById('sss').value = name_lbl;
</script>
</asp:Content>
任何人都有任何建议如何实现这一目标。
答案 0 :(得分:0)
而不是js,只需尝试使用C#代码从网格视图中获取值。
前:
int name_lbl = gvareadetails.Columns[0][0];
此处Columns[0][0]
为您提供第一行第一列值。
答案 1 :(得分:0)
从网格视图中获取值的C#代码:
string name_lbl;
protected void Page_Load(object sender, EventArgs e)
{
//---------------------------------------------
/// </summary>
/// /// <summary>
/// TO ACCESS COOKIE VARIABLE
/// </summary>
string b;
HttpCookie a = Request.Cookies["LangaugaeObj"];
if (a != null) b = a.Value; else b = "1";
if (b == "1")
{
name_lbl = "Hai";
}
else
{
name_lbl = "How are you";
}
//---------------------------------------------------
protected void Button1_Click(object sender, EventArgs e)
{
// here I set the variable name to the grid Header
gvareadetails.Columns[0].HeaderText = name_lbl;
Report report = new Report();
report.areaid = hidStatus.Value.ToString();
DataSet ds = report.getareawisedetails();
gvareadetails.DataSource = ds;
gvareadetails.DataBind();
ds.Dispose();
ds = null;
report = null;
}
感谢Shaji SS的建议。我希望这个答案能帮助那些在asp.net中使用asp:BoundField动态设置标题文本的人。