| |

VerySource

 Forgot password?
 Register
Search
View: 755|Reply: 9

Help! !! DataGrid template column issues ~~~~~~ online etc.

[Copy link]

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-5 19:00:01
| Show all posts |Read mode
HTML code:
<tr>
<TD align = "right"> <FONT face = "宋体"> Market price: </ FONT> </ TD>
<TD> <asp: Label id = "Label5" runat = "server">
<% # DataBinder.Eval (Container.DataItem, "price")%> </ asp: Label> </ TD>

<TD align = "right"> <FONT face = "宋体"> Member price: </ FONT> </ TD>
<TD> asp: Label id = "Label6" runat = "server">
<% # DataBinder.Eval (Container.DataItem, "priceA")%> </ asp: Label> </ TD>
</ tr>
Backstage:
if (! Page.IsPostBack) {BindData ();}
private void BindData ()
{
string sql = "select * from product";
SqlConnection conn = new SqlConnection (ConfigurationSettings.AppSettings ["zLSz_MySql"]);
SqlDataAdapter sda = new SqlDataAdapter (sql, conn);
DataTable dt = new DataTable ();
sda.Fill (dt);
dgInfo.DataSource = dt;
dgInfo.DataBind ();
}
I add the following code and I get an error:
Object reference is not set to an instance of the object.

private void dgInfo_ItemDataBound (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (Request.QueryString ["username"] == null)
{
That is the question of this sentence,
((Label) e.Item.FindControl ("Label7")). Text = ((Label) e.Item.FindControl ("Label5")). Text;
}
else
{
((Label) e.Item.FindControl ("Label7")). Text = ((Label) e.Item.FindControl ("Label6")). Text;
}
}
Why thank you
Reply

Use magic Report

0

Threads

23

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-3-24 10:30:01
| Show all posts
((Label) e.Item.cell [Column number] .FindControl ("Label7")). Text = ((Label) e.Item.cell [Column number] .FindControl ("Label5")). Text;
Reply

Use magic Report

0

Threads

23

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-3-24 11:45:02
| Show all posts
I don't know which row to look for.
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-3-25 00:15:01
| Show all posts
You can't use a serial number. mine
Label is the boss placed in the template column Tabel
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-3-25 09:45:01
| Show all posts
This is my entire DataGrid
<asp: datagrid id = "dgInfo" style = "Z-INDEX: 102; LEFT: 120px; POSITION: absolute; TOP: 304px" runat = "server"
Width = "800px" Height = "581px" GridLines = "None" AutoGenerateColumns = "False">
<Columns>
<asp: TemplateColumn>
<ItemTemplate>
<P> <FONT face = "宋体"> </ FONT> </A> </ P>
<P>
<TABLE id = "Table1" style = "WIDTH: 744px; HEIGHT: 155px" cellSpacing = "1" cellPadding = "1"
width = "744" border = "1">
<TR>
<TD rowSpan = "4">
<asp: Image id = Image1 runat = "server" Width = "168px" Height = "165px" ImageUrl = '<% # FormatImage (DataBinder.Eval (Container.DataItem, "id"))%>'>
</ asp: Image> </ TD>
</ TR>
<TR>
<TD align = "right"> <FONT face = "宋体"> Product name: </ FONT> </ TD>
<TD colSpan = "5">
<asp: Label id = "Label1" runat = "server">
<% # DataBinder.Eval (Container.DataItem, "pname")%>
</ asp: Label> <FONT face = "宋体">&nbsp;&nbsp;
<asp: Label id = "Label2" runat = "server">
<% # DataBinder.Eval (Container.DataItem, "code")%>
</ asp: Label> </ FONT> </ TD>
</ TR>
<TR>
<TD align = "right"> <FONT face = "宋体"> Number: </ FONT> </ TD>
<TD> <FONT face = "宋体">&nbsp;
<asp: TextBox id = "TextBox1" runat = "server" BorderStyle = "Groove" Width = "32px"> 1 </ asp: TextBox>
<asp: Button id = "Button1" runat = "server" Text = "<<" CommandName = "ADD"> </ asp: Button>
<asp: Button id = "Button2" runat = "server" Text = ">>" CommandName = "ADD1"> </ asp: Button>&nbsp;
</ FONT>
</ TD>
<TD align = "right"> <FONT face = "宋体"> Gifts: </ FONT> </ TD>
<TD>
<asp: Label id = "Label4" runat = "server">
<% # DataBinder.Eval (Container.DataItem, "score")%>
</ asp: Label> </ TD>
<TD align = "right"> <FONT face = "宋体"> Market price: </ FONT> </ TD>
<TD>
<asp: Label id = "Label5" runat = "server">
<% # DataBinder.Eval (Container.DataItem, "price")%>
</ asp: Label> </ TD>
</ TR>
<TR>
<TD align = "right"> <FONT face = "宋体"> Member price: </ FONT> </ TD>
<TD>
<asp: Label id = "Label6" runat = "server">
<% # DataBinder.Eval (Container.DataItem, "priceA")%>
</ asp: Label> </ TD>
<TD align = "right"> <FONT face = "宋体"> Transaction price: </ FONT> </ TD>
<TD>
<asp: Label id = "Label7" runat = "server"> Label </ asp: Label> </ TD>
<TD align = "right"> <FONT face = "宋体"> Total: </ FONT> </ TD>
<TD>
<asp: Label id = "Label8" runat = "server"> Label </ asp: Label> </ TD>
</ TR>
</ TABLE>
</ P>
</ ItemTemplate>
</ asp: TemplateColumn>
</ Columns>
</ asp: datagrid>
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-30 11:30:01
| Show all posts
Your current serial number is 0
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-3-31 13:30:01
| Show all posts
How can I get it?
Thank you
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-3-31 18:15:01
| Show all posts
((Label) e.Item.FindControl ("Label6")). Text
Where Label6 is the ID of my label,
Reply

Use magic Report

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-4-1 08:15:01
| Show all posts
The template column is the number of columns
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-4-1 16:00:01
| Show all posts
Template column 5
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list