596
צפיות
צפיות
10
תשובות
תשובות
שלום…
אני בונה אתר….
ובניתי מסך שיוצר כפתורים דינמיים.
בצורה כזאת הוא מייצר panel ועל ה – panel הוא בונה label listbox and button
ברגע שאני לוחץ על button יצרתי לו event והוא צריך לבדוק ב – listbox איזה שורות סומנו….
ב – event אני יודע מה ה – id של ה – button שהוא גם ה – id של ה – listbox
והשאלה היא כזאת :
איך אני יכול לגשת ל – listbox הזה…?
נ.ב.
אני עובד ב – asp.net וכותב ב – c#
תודה איתי.
10 תשובות
תעשה טובה לעצמך
ואל תשתמש ב Panel, זה פקד מגעיל.
וחוץ מזה
יש לך תשובה איך אפשר לעשות את זה…?
ואולי אתר שיש בו חומר על webusercontrol כי נראה לי שזאת הדרך הטובה ביותר…?
תודה רבה על העזרה
איתי.
בעקרון זה מתבצע כך:
objListBox.SelectedItem.Value;
או
objListBox.SelectedIndex;
לקבל הערך המספר של השדה שסומן
אני יודע את זה אבל…
שאני מבצע בנייה של listboxs ו buttons באופן דינמי ב – from_load ואז אני בונה event click ל – button אני לא מצליח לגשת ל – listbox.
הנה חלק מהקוד…
public static Panel PanelDB = new Panel ();
public static Button BtnAddTables = new Button();
public static ListBox ListDBTables = new ListBox();
public static Label LblDBName = new Label();
void BtnAddTables_Click(object sender, System.EventArgs e)
{
for ( ;Count>=0;Count–)
{
Button currentButton = (Button)sender;
if(currentButton.ID == "BtnAddTables" + Count)
{
}
}
}
private void Page_Load(object sender, System.EventArgs e)
{
for (int Index=0;Index < ListHelp.Items.Count;Index+=3)
{
PanelDB = new Panel ();
BtnAddTables = new Button();
ListDBTables = new ListBox();
LblDBName = new Label();
LblDBName.ID = "LblDBName" + Index;
LblDBName.Width = 100; LblDBName.Height = 24;
LblDBName.Text = "hello world";
ListDBTables.ID = "ListDBTables" + Index;
ListDBTables.Width = 200;
ListDBTables.Height = 200;
ListDBTables.SelectionMode = ListSelectionMode.Multiple;
BtnAddTables.ID = "BtnAddTables" + Index;
BtnAddTables.Width = 200;
BtnAddTables.Height = 24;
BtnAddTables.DataBind();
BtnAddTables.AccessKey = Count.ToString () ;
BtnAddTables.Text = "הוסף טבלה/ות";
BtnAddTables.Click+= new EventHandler(this.BtnAddTables_Click);
PanelDB.ID = "PanelDB" + Index;
PanelDB.Height = 250;
PanelDB.Width = 200;
PanelDB.Style["top"] = top.ToString();
PanelDB.Style["left"] = left.ToString();
PanelDB.Style["position"] = "absolute";
PanelDB.HorizontalAlign = HorizontalAlign.Center;
PanelDB.BorderColor = Color.Blue;
PanelDB.BorderWidth = 2;
PanelDB.Controls.Add(LblDBName);
PanelDB.Controls.Add(new LiteralControl("<br>"));
PanelDB.Controls.Add(ListDBTables);
PanelDB.Controls.Add(new LiteralControl("<br>"));
PanelDB.Controls.Add(BtnAddTables);
Form1.Controls.Add(PanelDB);
left = left + 210;
LblDBName.Text = ListHelp.SelectedValue;
ListHelp.SelectedIndex = Index+1
מה שאני לא מצליח זה ב – event של ה – button להגיע ל – listbox שנמצא איתו.
בתודה איתי.
|חבול|
למה אתה עושה את כל ה-style בצד השרת ?!
תשתמש ב-CSS
אם תמשיך ככה האפליקציה שלך תהיה איטית כמו צב |חבול|
כן אתה צודק…
תודה…
אבל יש לך אולי פתרון לשאלה האמיתית
בתודה איתי.
נ.ב.
זאת סתם דוגמא.
לא יודע ASP.NET מצטער :-/
יש לי עוד שאלה…
בנית web user control ב – asp.net.
אני רוצה לעלות את ה – web user controls בצורה דינמית ולהשתמש בהם ב – user control עצמו.
משום מה הוא מביא לי את השגיאה הבאה….
Multiple controls with the same ID '_ctl0' were found. FindControl requires that controls have unique IDs
אם למישהו יש רעיון אשמח לשמוע בשאלות הקודמות הסברתי מה אני רוצה לבצע פחות או יותר…
בתודה איתי.
יש לי שאלה על css
מישהן יכול לתת לי דוגמא או קצת מידע איך בונים css ל – web control לדומא ל – panel וכו'
תודה איתי.
אתה בונה קלאס רגיל
של CCS (לא קלאס בשפת תכנות אלא קלאס של CSS)
<style type="text/css">
.aClass{
/** CSS CODE */
}
</style>
ואז משייך אותו ל-web control ע"י ה-attribute: class
סתם שאלה
למה אתה משתמש ב-web control ? כי שמעתי שכל מה שעושים עםweb control אפשר לעשות גם עם DHTML