DropDownList의 너비를 가져 오려고하고 있는데, 그 끝에 "px"가 계속 이어집니다. 최종 결과는 DropDownList의 모든 항목의 너비를 결정하여 프로그래밍 방식으로 너비를 설정할 수 있습니다.INT 형식의 DropDownList의 너비를 가져 오려고 시도합니다.
public static int FindTheWidth(object sender)
{
DropDownList senderComboBox2 = (DropDownList)sender;
// int width = senderComboBox.Width;
var s = senderComboBox2.Width;
var CBW = s.SubString(0, s.IndexOf("p"));
int width2 = Convert.ToInt32(CBW);
int vertScrollBarWidth = 2;
int newWidth;
foreach (string s in ((DropDownList)sender).Items)
{
newWidth = width2 + vertScrollBarWidth;
if (width2 < newWidth)
{
width2 = newWidth;
}
}
senderComboBox2.Width = width2;
return width2;
}
어떤 아이디어 : 여기
내가 가진 무엇인가?
실제 너비는 클라이언트에서만 사용할 수 있습니다. –
당신은 클라이언트 측에서 이것을 위해 약간의 Javascript/CSS를 사용하고 싶을 것입니다. 서버 코드는 프리젠 테이션 레이어가 무엇을하고 있는지 알지 못합니다 (글꼴 크기 등) – geedubb